当前位置: 技术问答>java相关
请教String To Date 的方法。
来源: 互联网 发布时间:2015-03-03
本文导语: 怎么样用一字符串"Wed Dec 12 10:29:00 CST 2001"生成 Date对象? 然后又怎么样Format成"2001-12-12 10:29:00"的字符串? | String ds="Wed Dec 12 10:29:00 CST 2001"; DateFormat df = DateFormat.getDateInstance(); try ...
怎么样用一字符串"Wed Dec 12 10:29:00 CST 2001"生成 Date对象?
然后又怎么样Format成"2001-12-12 10:29:00"的字符串?
然后又怎么样Format成"2001-12-12 10:29:00"的字符串?
|
String ds="Wed Dec 12 10:29:00 CST 2001";
DateFormat df = DateFormat.getDateInstance();
try {
Date d = df.parse(ds);
}
catch(ParseException e) {
System.out.println("Unable to parse " + ds);
}
DateFormat df = DateFormat.getDateTimeInstance();
String s = df.format(d);
System.out.println("day is " + s);
DateFormat df = DateFormat.getDateInstance();
try {
Date d = df.parse(ds);
}
catch(ParseException e) {
System.out.println("Unable to parse " + ds);
}
DateFormat df = DateFormat.getDateTimeInstance();
String s = df.format(d);
System.out.println("day is " + s);
|
import java.util.*;
import java.text.*;
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM,
Locale.CHINA);
String myString = df.format( new Date() )
import java.text.*;
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM,
Locale.CHINA);
String myString = df.format( new Date() )
|
Date now_time=new Date();
int year=now_time.getYear()+1900;
int month=now_time.getMonth()+1;
int day=now_time.getDate();
int hour=now_time.getHours();
int minute=now_time.getMinutes();
int second=now_time.getSeconds();
int year=now_time.getYear()+1900;
int month=now_time.getMonth()+1;
int day=now_time.getDate();
int hour=now_time.getHours();
int minute=now_time.getMinutes();
int second=now_time.getSeconds();