乔达 时区计算

发布于 2024-12-11 17:41:31 字数 667 浏览 1 评论 0原文

一直在研究 Joda 时区,发现以下内容似乎很奇怪。

我运行了以下代码

    DateTimeZone gmt = DateTimeZone.forID( "Etc/GMT" );
    DateTimeZone gmtPlusOne = DateTimeZone.forID( "Etc/GMT+1" );
    DateTimeZone gmtMinusOne = DateTimeZone.forID( "Etc/GMT-1" );

    System.out.println( new DateTime( gmt ).toString() );
    System.out.println( new DateTime( gmtPlusOne ).toString() );
    System.out.println( new DateTime( gmtMinusOne ).toString() );

并得到了以下输出,

2011-10-24T13:00:12.890Z
2011-10-24T12:00:12.937-01:00
2011-10-24T14:00:12.937+01:00

我有点惊讶地看到“gmtPlusOne”以 -01:00 落后一小时而“gmtMinusOne”则相反。有人能解释一下为什么这些结果会像我预期的相反吗?

Been playing around with Joda timezones and found the following which seemed odd.

I ran the following code

    DateTimeZone gmt = DateTimeZone.forID( "Etc/GMT" );
    DateTimeZone gmtPlusOne = DateTimeZone.forID( "Etc/GMT+1" );
    DateTimeZone gmtMinusOne = DateTimeZone.forID( "Etc/GMT-1" );

    System.out.println( new DateTime( gmt ).toString() );
    System.out.println( new DateTime( gmtPlusOne ).toString() );
    System.out.println( new DateTime( gmtMinusOne ).toString() );

And got the following output

2011-10-24T13:00:12.890Z
2011-10-24T12:00:12.937-01:00
2011-10-24T14:00:12.937+01:00

I was a bit suprised to see "gmtPlusOne" coming out as one hour behind with -01:00 and the reverse for "gmtMinusOne". Can someone explain why these come out like this as I would have expected the opposite.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2024-12-18 17:41:31

这个文档解释了这种不那么直观的行为的原因。它表示 Etc/GMT+1 的标准偏移量为 -1:00,而 Etc/GMT-1 的标准偏移量为 >+1:00。这种偏移量的逆转适用于任何 Etc/GMT+n

来自 wiki

Etc的特殊区域用于一些行政区域,
特别是对于“Etc/UTC”,它代表协调通用
时间。为了符合 POSIX 风格,这些区域名称
以“Etc/GMT”开头的符号与大多数符号相反
人们期待。在这种风格中,GMT 以西的区域有一个正号
那些东方人的名字里有一个负号(例如“Etc/GMT-14”是
格林威治标准时间 (GMT) 提前/以东 14 小时。)

This documentation explains the reason for this not so intuitive behavior. It says Etc/GMT+1 has a standard offset of -1:00 and Etc/GMT-1 has a standard offset of +1:00. This reversal of offset holds for any Etc/GMT+n.

From wiki

The special area of Etc is used for some administrative zones,
particularly for "Etc/UTC" which represents Coordinated Universal
Time. In order to conform with the POSIX style, those zone names
beginning with "Etc/GMT" have their sign reversed from what most
people expect. In this style, zones west of GMT have a positive sign
and those east have a negative sign in their name (e.g "Etc/GMT-14" is
14 hours ahead/east of GMT.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文