服務(wù)熱線
153 8323 9821
1、
字符串轉(zhuǎn)換成日期時(shí)間格式
//日期時(shí)間格式:yyyy-MM-dd hh:mm:ss
String time ="1900-02-21 12:23:33";
//將字符串轉(zhuǎn)換為日期和時(shí)間
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//生成的日期和時(shí)間
Date date = dateformat .parse(time);
date就是我們想要的
如果程序中有2個(gè)或2個(gè)以上的地方調(diào)用了dateformat.parse()方法,則有可能會(huì)報(bào)錯(cuò):Unhandled exception type ParseException。
為此,需要利用try-catch塊來(lái)捕捉:
try{
dateformat .parse(time);
} catch(Exception e) {
e.printStackTrace();
}
http://www.cnblogs.com/pricks/archive/2009/06/05/1497193.html
2、
字符串轉(zhuǎn)換為日期型(C#)
如:"20071107"轉(zhuǎn)換成日期型?
"20071107"轉(zhuǎn)換成int型怎么轉(zhuǎn)換??
1、DateTime dt=Convert.ToDateTime("20071107".Substring(0,4)+"-"+"20071107".Substring(4,2)+"-"+"20071107".Substring(6,2));
int i=Convert.ToInt32("20071107");
2、Convert.ToDateTime、DateTime.Parse()
3、string str = "20071107";
DateTime dt = DateTime.ParseExact(str, "yyyyMMdd", null);
int i;
int.TryParse(str, out i);
4、定義一個(gè)DateTimePicker對(duì)象,然后將需要轉(zhuǎn)化的字符串賦給這個(gè)DateTimePicker對(duì)象的Text屬性,
然后DateTimePicker對(duì)象的Value值就是你需要的日期和時(shí)間,Value值還有Minite,Second等屬性,可以取得
時(shí),分,秒,豪秒等值.
http://hi.baidu.com/sunygis/blog/item/e3bb13faa0f449116d22eb8a.html