java - 为什么 java.time.ZoneOffset 实例排序为 'backwards' ?

标签 java timezone timezone-offset

来自documentation :

The offsets are compared in the order that they occur for the same time of day around the world. Thus, an offset of +10:00 comes before an offset of +09:00 and so on down to -18:00.

有谁知道他们被这样排序的原因吗?这似乎违反直觉,因为它与偏移量的数值顺序相反。这也与它们在以 GMT/UTC+0 为中心的 map 上从左到右阅读的顺序相反。

(旁白:我不明白为什么引用的文档提到“低至 -18:00”。-12:00 或 -24:00 我会理解。为什么 -18:00?如果你打印输出所有支持的 java.time.ZoneId 时区的偏移量,它们的范围从 -11:00 到 +12:00。)

更新:对我的回答。来自同一文档的其他地方:

In 2008, time-zone offsets around the world extended from -12:00 to +14:00. To prevent any problems with that range being extended, yet still provide validation, the range of offsets is restricted to -18:00 to 18:00 inclusive.

最佳答案

假设您有一个本地化的日期/时间列表,以及某个事件发生时的相关时区:

(1) 2016/05/26 00:00:00 in Australian Eastern Standard Time (UTC+10)
(2) 2016/05/26 00:00:00 in Greenwich Mean Time (UTC+0)
(3) 2016/05/26 00:00:00 in Japan Standard Time (UTC+9)

您可以将这些时间转换为单一时区的时间,例如格林威治标准时间:

(1) 2016/05/25 14:00:00 GMT
(2) 2016/05/26 00:00:00 GMT
(3) 2016/05/25 15:00:00 GMT

现在按照“先发生的”顺序对它们进行排序:

(1) 2016/05/25 14:00:00 GMT
(3) 2016/05/25 15:00:00 GMT
(2) 2016/05/26 00:00:00 GMT

所以澳大利亚时间 (1) 在日本时间 (3) 之前,日本时间 (3) 在英国时间 (2) 之前。

它只是对时区应用相同的顺序:正如引述所说:

The offsets are compared in the order that they occur for the same time of day around the world

因此澳大利亚东部标准时间被认为“早于”日本标准时间,日本标准时间被认为“早于”格林威治标准时间。

关于java - 为什么 java.time.ZoneOffset 实例排序为 'backwards' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458275/

相关文章:

java - 该函数是否使用了太多检查和变量?

java - Libgdx Scene2d 表和滚动 Pane 错误?

kubernetes - cronjob 在 AWS EKS 集群中使用 UTC 时区运行

go - 获取完整的 UTC 偏移量格式

python - 使用 pytz 从 UTC 偏移 "Canonical"?

java - 按下取消按钮时 Swing DataBinding 回滚发生变化

java - Java 中的引用

mysql - 如何将带有 current_timestamp 的本地时区详细信息作为 mysql 中列的默认值

windows - 如何从命令行设置时区?

sql - Postgresql 时区转换