Joda Time – 时区之间的差异

我想用Joda时间将当前时间转换为特定时区的时间。

有没有办法将DateTime time = new DateTime()转换为特定时区,或者可能是为了得到time.getZone()和另一个DateTimeZone之间的小时数差异,然后再做time.minusHourstime.plusHours

我想用Joda时间将当前时间转换为特定时区的时间。

你是否已经获得当前时间并不是很清楚。 如果你已经拥有它,你可以使用withZone

 DateTime zoned = original.withZone(zone); 

如果您只是获取当前时间,请使用适当的构造函数 :

 DateTime zoned = new DateTime(zone); 

或使用DateTime.now

 DateTime zoned = DateTime.now(zone); 

查看DateTimeZone&Interval at
http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTimeZone.html&http://joda-time.sourceforge.net/apidocs/org/joda/time/Interval.html

 DateTime dt = new DateTime(); // translate to London local time DateTime dtLondon = dt.withZone(DateTimeZone.forID("Europe/London")); 

间隔:

 Interval interval = new Interval(start, end); //start and end are two DateTimes