//毫秒轉換為日期
public static void main(String[] args) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
System.out.println(now + " = " + formatter.format(calendar.getTime()));
// 日期轉換為毫秒 兩個日期想減得到天數
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String start="2011-09-20 12:30:45";
String end ="2011-10-20 6:30:00";
//得到毫秒數
long timeStart=sdf.parse(start).getTime();
long timeEnd =sdf.parse(end).getTime();
//兩個日期想減得到天數
long dayCount= (timeEnd-timeStart)/(24*3600*1000);
System.out.println(dayCount);
}