import java.util.*; |
import java.text.*; |
public class Test { |
public static void main(String args[]) { |
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss SSS" ); |
Date d = new Date(); |
//把当前时间转换成为我们熟悉的时间表达格式 |
String str = df.format(d); |
System.out.println(" |
当前 |
时间是:"+str); |
//然后再把字符串格式的日期转换成为一个Date类 |
try { |
Date d2 = df.parse( "2008-08-08 08:08:08 888" ); |
System.out.println(" |
北京奥运会开幕时间是:"+d2.getTime()); |
} catch (ParseException e) { |
e.printStackTrace(); |
} |
} |
} //源代码片段来自云代码http://yuncode.net |
|