本文介紹了時區、日歷和 SimpleDateFormat 的奇怪問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
讓我們考慮以下代碼:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy", Locale.US);
long start = sdf.parse("10:30:00 30/09/2009").getTime();
long end = sdf.parse("10:30:00 30/10/2009").getTime();
Calendar c = Calendar.getInstance(Locale.US);
c.setTimeInMillis(start);
System.out.println("Start = " + c.getTime());
c.setTimeInMillis(end);
System.out.println(" End = " + c.getTime());
運行此代碼段時,我有以下輸出:
When running this code snippet, I have the following output:
Start = Wed Sep 30 10:30:00 CEST 2009
End = Fri Oct 30 10:30:00 CET 2009
為什么我得到不同的時區?
Why do I get different timezone ?
請注意,如果我將第一個日期設置為 8 月,第二個日期設置為 9 月,則兩種情況下的輸出將顯示相同的時區:
Note that if I set the first date in august and the second one in september, the output will display the same timezone in both cases:
long start = sdf.parse("10:30:00 30/08/2009").getTime();
long end = sdf.parse("10:30:00 30/09/2009").getTime();
將顯示:
Start = Sun Aug 30 10:30:00 CEST 2009
End = Wed Sep 30 10:30:00 CEST 2009
我使用的是 Java 1.6.0_14
I'm using Java 1.6.0_14
推薦答案
CEST
是中歐夏令時.與夏令時生效的 CET
相同.
CEST
is Central European Summer Time. It is the same as CET
with daylight savings into effect.
這篇關于時區、日歷和 SimpleDateFormat 的奇怪問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!