乔达时间 - 时区之间不同

问题描述 投票:10回答:2

我想当前时间转换为时间与乔达时间特定的时区。

有没有一种方法来DateTime time = new DateTime()转换为特定的时区,或者获得time.getZone()和另一DateTimeZone小时之间差异的数量然后做time.minusHourstime.plusHours

java datetime timezone jodatime
2个回答
27
投票

我想当前时间转换为时间与乔达时间特定的时区。

这是不是真的清楚你是否已经有当前时间或没有。如果你已经有了它,你可以使用withZone

DateTime zoned = original.withZone(zone);

如果你只是获取当前时间,使用appropriate constructor

DateTime zoned = new DateTime(zone);

或使用DateTime.now

DateTime zoned = DateTime.now(zone);

8
投票

退房DateTimeZoneInterval

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
© www.soinside.com 2019 - 2024. All rights reserved.