我想当前时间转换为时间与乔达时间特定的时区。
有没有一种方法来DateTime time = new DateTime()
转换为特定的时区,或者获得time.getZone()
和另一DateTimeZone
小时之间差异的数量然后做time.minusHours
或time.plusHours
?
我想当前时间转换为时间与乔达时间特定的时区。
这是不是真的清楚你是否已经有当前时间或没有。如果你已经有了它,你可以使用withZone
:
DateTime zoned = original.withZone(zone);
如果你只是获取当前时间,使用appropriate constructor:
DateTime zoned = new DateTime(zone);
或使用DateTime.now
:
DateTime zoned = DateTime.now(zone);
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