//=== 取得今天日期===
Date date = new Date();
SimpleDateFormat bartDateFormat = new
SimpleDateFormat("yyyyMMdd");
String str = bartDateFormat.format(date);
System.out.println(str); //得到 20100625
//=== 自訂日期轉 Date===
String date = "2010/06/09" ;
String time1 = "08:42:40" ;
String time2 = "08:42:45" ;
String datetime1 = date + " " + time1 ;
String datetime2 = date + " " + time2 ;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date dt1 = sdf.parse( datetime1 );
System.out.println(dt1); //得到 Wed Jun 09 08:42:40 CST 2010
Date dt2 = sdf.parse( datetime2 );
System.out.println(dt2); //得到 Wed Jun 09 08:42:45 CST 2010
long dt_diff = (dt2.getTime() - dt1.getTime()) / 1000 ; //轉成秒
System.out.println(dt_diff); //得到 5 secs
留言列表