Java – identify future time zone transitions

I need to predict that the next transition of at least 2 time zones will be a specific time zone

Java 8 provides a new Java Time API, especially Java time. zone. ZoneRules. Gettransitions () looks like what I need, but it doesn't list "Australia / Sydney" after 2010

What is the most reliable way to determine the date / time / offset of the next 2 time zone conversion?

Solution

Method zonerules Gettransitions () does not list all the transformations up to infinity in the future (obviously) This will result in the next two transformations:

ZoneId zoneId = ZoneId.of("Australia/Sydney");
ZoneRules rules = zoneId.getRules();

ZoneOffsetTransition nextTransition = rules.nextTransition(Instant.Now());
System.out.println("Next transition at: " +
        nextTransition.getInstant().atZone(zoneId));

ZoneOffsetTransition nextNextTransition =
        rules.nextTransition(nextTransition.getInstant());
System.out.println("Next transition after that at: " +
        nextNextTransition.getInstant().atZone(zoneId));

Output:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>