2012-04-03 127 views

回答

3

使用withZone()將Joda-Time對象轉換爲不同的時區。

+3

謝謝,對於這種特殊情況,我使用了DateTimeZone.forID(「America/New_York」); – BillMan 2012-04-19 15:04:39

2

喬達自己照顧它。使用TimeZone和某個地方的Locale之間有細微差別。

看看下面的例子。

使用語言環境:

使用@ BillMan的建議設置DateTimeZone的區域實際上將更改時區。

System.out.println("Winter " + DateTime.now(DateTimeZone.UTC).parse("2015-12-01T12:00:00").toDateTime(DateTimeZone.forID("America/New_York")).toString()); 
System.out.println("Summer " + DateTime.now(DateTimeZone.UTC).parse("2015-05-01T12:00:00").toDateTime(DateTimeZone.forID("America/New_York")).toString()); 

返回:

Winter 2015-12-01T12:00:00.000-05:00 
Summer 2015-05-01T12:00:00.000-04:00 

使用時區:

注意這兩個時間設置爲12:00:00,結果在夏季得到了由一個小時移動,(但偏移保持不變)

System.out.println("Winter " + DateTime.now(DateTimeZone.UTC).parse("2015-12-01T12:00:00").toDateTime(DateTimeZone.forID("EST")).toString()); 
System.out.println("Summer " + DateTime.now(DateTimeZone.UTC).parse("2015-05-01T12:00:00").toDateTime(DateTimeZone.forID("EST")).toString()); 

返回:

Winter 2015-12-01T12:00:00.000-05:00 
Summer 2015-05-01T11:00:00.000-05:00 
+0

EDT!= EST。在美國東海岸,美國東部時間和美國東部時間之間的時間變化,反之亦然。這樣做的結果是,您向前移動時跳過一個小時,並在返回時有兩個1:00 AM。 – BillMan 2015-12-16 20:01:11

+0

喬達沒有EDT時區。 美國東部時間確實考慮到夏令時間的差異。 – 2015-12-17 01:48:24

+0

EST是一個常數,落後UTC時間-05:00。如果你能提供證據不是的話,我會很樂意接受。見http://www.timeanddate.com/time/zones/est – BillMan 2015-12-17 14:49:25