程序後跟輸出。有人請向我解釋爲什麼從1970年1月1日開始的10,000,000毫秒是1969年11月31日。那麼請有人解釋我的假設:第一次測試應該從1970年1月1日開始產生10,000,000毫秒的時間,這是錯誤的。相同的結果。Java.util.Calendar - 1970年1月1日以來的毫秒數
public static void main(String[] args) {
String x = "10000000";
long l = new Long(x).longValue();
System.out.println("Long value: " + l);
Calendar c = new GregorianCalendar();
c.setTimeInMillis(l);
System.out.println("Calendar time in Millis: " + c.getTimeInMillis());
String origDate = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH);
System.out.println("Date in YYYY-MM-DD format: " + origDate);
x = "1000000000000";
l = new Long(x).longValue();
System.out.println("\nLong value: " + l);
c.setTimeInMillis(l);
System.out.println("Calendar time in Millis: " + c.getTimeInMillis());
origDate = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH);
System.out.println("Date in YYYY-MM-DD format: " + origDate);
}
Long值:千萬
日曆時間以毫秒:千萬
日期的YYYY-MM-DD格式爲:1969年11月31日
Long值:萬億
Millis日曆時間:1000000000000
在YYYY-MM-DD格式的日期:2001年8月8日
謝謝!我以爲我瘋了。 – 2008-11-05 00:39:48