包com.ob; 导入Java.text.parse exception; 导入Java.text.simple date format; import java.util.Calendar; import java.util.Date; publicclassdatetest { publicstaticvoidmain (字符串[ ] args ) throwsparseexception { calendar now=calendar.getinstance } } System.out.println (月: () now.get (calendar.month )1) ) ); System.out.println ('日:'now.get ) Calendar.day_of_month ); System.out.println (时: now.get ) calendar.hour_of_day ) ); System.out.println (分: ) now.get ) calendar.minute ); System.out.println (秒: ) now.get ) calendar.second ); System.out.println (当前时间毫秒) now.getTimeInMillis ); system.out.println(now.gettime ); 日期d=new date (; 系统. out.println (d; simpledateformatsdf=newsimpledateformat (yyyy-mm-ddhh : mm : ss ); stringdatenowstr=SDF.format(d; System.out.println ('格式化日期: ' dateNowStr ); stringstr=' 2012-1-1317336026336033 '; //与上面的sdf定义的格式相同,datetoday=SDF.parse(str ); System.out.println ) )字符串已转换为日期。 (托日); }输出结果:
年: 2012
月: 1
日: 13
时: 17
分: 28
秒: 19
当前时间毫秒数: 1326446899902
Fri Jan 13 17:28:19 CST 2012
Fri Jan 13 17:28:19 CST 2012
格式化后的日期: 2012-01-13 17:28:19
字符串转换日期: Fri Jan 13 17:26:33 CST 2012