确定未来的时区转换 [英] Determine future timezone transitions

查看:166
本文介绍了确定未来的时区转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要预测下一个至少2个时区转换何时适用于特定时区。

I need to predict when the next at least 2 timezone transitions will be for a particular timezone.

Java 8提供新的 java。时间 API,特别是 java.time.zone ZoneRules.getTransitions()看起来正是我需要的,但它没有列出2010年以后澳大利亚/悉尼的任何内容。

Java 8 offers the new java.time API, specifically java.time.zone. ZoneRules.getTransitions() looks like exactly what I need however it doesn't list anything beyond the year 2010 for "Australia/Sydney".

确定下2个时区转换的日期/时间/偏移的最可靠方法是什么?

What is the most reliable way to determine the next 2 timezone transition's date/time/offset?

推荐答案

方法 ZoneRules.getTransitions()未列出所有转换,直到将来无限(显然)。这将获得接下来的两个转换:

The method ZoneRules.getTransitions() doesn't list all transitions until infinity into the future (obviously). This gets the next two transitions:

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));

输出:


下一次转换时间:2016-10-02T03:00 + 11:00 [澳大利亚/悉尼]

Next transition at: 2016-10-02T03:00+11:00[Australia/Sydney]

之后的下一次转换:2017-04-02T02: 00 + 10:00 [澳大利亚/悉尼]

Next transition after that at: 2017-04-02T02:00+10:00[Australia/Sydney]

这篇关于确定未来的时区转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆