But how could you live and have no story to tell!
访问统计 original graphics

如:"20100101"转换成日期型?

"20100101"转换成int型怎么转换??

1、DateTime dt=Convert.ToDateTime("20100101".Substring(0,4)+"-"+"20100101".Substring(4,2)+"-"+"20071107".Substring(6,2));
int i=Convert.ToInt32("20100101");

2、Convert.ToDateTime、DateTime.Parse()

3、string str = "20100101";
DateTime dt
= DateTime.ParseExact(str, "yyyyMMdd", null);
int i;
int.TryParse(str, out i);

4、定义一个DateTimePicker对象,然后将需要转化的字符串赋给这个DateTimePicker对象的Text属性,
然后DateTimePicker对象的Value值就是你需要的日期和时间,Value值还有Minite,Second等属性,可以取得
时,分,秒,豪秒等值.

 

√JAVA字符串转换成日期时间格式

//日期时间格式:yyyy-MM-dd hh:mm:ss
String time ="1900-02-21 12:23:33";
//将字符串转换为日期和时间
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//生成的日期和时间
Date date = dateformat .parse(time);

date就是我们想要的

 

如果程序中有2个或2个以上的地方调用了dateformat.parse()方法,则有可能会报错:Unhandled exception type ParseException。

为此,需要利用try-catch块来捕捉:

  try{
dateformat .parse(time);
} catch(Exception e) {
e.printStackTrace();
}

posted on 2012-08-29 15:42  nextsoft  阅读(6285)  评论(0编辑  收藏  举报