【问题标题】:Joda time zone calculation乔达时区计算
【发布时间】:2011-10-24 13:06:28
【问题描述】:

一直在玩 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”则相反。有人可以解释为什么这些结果会像我预期的相反。

【问题讨论】:

  • 别担心 Jon 随时都会来 ;-)

标签: java timezone jodatime


【解决方案1】:

documentation 解释了这种不那么直观的行为的原因。它说Etc/GMT+1 的标准偏移量为-1:00Etc/GMT-1 的标准偏移量为+1:00。这种偏移反转适用于任何Etc/GMT+n

来自wiki

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

【讨论】:

  • Apple 在this text file 中讨论了这个 POSIX 问题。 We use POSIX-style signs in the Zone names and the output abbreviations, even though this is the opposite of what many people expect. POSIX has positive signs west of Greenwich, but many people expect positive signs east of Greenwich. For example, TZ='Etc/GMT+4' uses the abbreviation "GMT+4" and corresponds to 4 hours behind UTC (i.e. west of Greenwich) even though many people would expect it to mean 4 hours ahead of UTC (i.e. east of Greenwich).
  • 这些Etc 应该是不必要的。使用proper time zone name,通常是大陆+斜线+城市/地区,例如Asia/KolkataAmerica/Montreal
猜你喜欢
  • 2015-11-28
  • 1970-01-01
  • 2013-03-18
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-12
  • 2021-08-17
相关资源
最近更新 更多