本文介紹了時(shí)區(qū)、日歷和 SimpleDateFormat 的奇怪問(wèn)題的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
讓我們考慮以下代碼:
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());
運(yùn)行此代碼段時(shí),我有以下輸出:
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
為什么我得到不同的時(shí)區(qū)?
Why do I get different timezone ?
請(qǐng)注意,如果我將第一個(gè)日期設(shè)置為 8 月,第二個(gè)日期設(shè)置為 9 月,則兩種情況下的輸出將顯示相同的時(shí)區(qū):
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
是中歐夏令時(shí).與夏令時(shí)生效的 CET
相同.
CEST
is Central European Summer Time. It is the same as CET
with daylight savings into effect.
這篇關(guān)于時(shí)區(qū)、日歷和 SimpleDateFormat 的奇怪問(wèn)題的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!