简体   繁体   English

Joda-Time DateTimeZone

[英]Joda-Time DateTimeZone

I have a unit test which attempts to verify some behavior between Israel/London, one of the first things I check is the timezone offset in Asia/Jerusalem as follows 我有一个单元测试试图验证以色列/伦敦之间的一些行为,我检查的第一件事是Asia/Jerusalem的时区偏移,如下所示

val clientTimezone = DateTimeZone.forID("Asia/Jerusalem")
val now = new DateTime(DateTimeZone.forID("Etc/GMT"))
val clientOffset = clientTimezone.getOffset(now) / (1000 * 60)

Right now it's 5pm in London, 7pm in Israel, and 4pm GMT, but when I run this code I get now initialized to 16:00, and clientOffset = 120 not 180. If I swap Asia/Jerusalem for Europe/London I get a clientOffset = 60. 现在是伦敦的下午5点,以色列的晚上7点和格林威治标准时间下午4点,但是当我运行此代码时,我now初始化为16:00, clientOffset = 120而不是180.如果我将Asia/Jerusalem换成Europe/London我会得到一个clientOffset = 60。

Am I using Joda correctly, or does it have the wrong time? 我正确使用Joda,还是错误的时间? These tests were fine before this weekend. 这个周末之前这些测试都没问题。 This is with version joda-time 2.1 这是版本joda-time 2.1

The time zone rules for Israel have changed. 以色列的时区规则发生了变化。 You'll need to use the 2013d version of the IANA time zone database. 您需要使用2013年版的IANA时区数据库。 This is included in JodaTime 2.3. 这包含在JodaTime 2.3中。

If you can't update JodaTime, you can update the TZDB data separately following these instructions . 如果无法更新JodaTime,则可以按照这些说明单独更新TZDB数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM