TimeZone casablanca (java) 的错误偏移 [英] Wrong offset for TimeZone casablanca (java)

查看:21
本文介绍了TimeZone casablanca (java) 的错误偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在卡萨布兰卡时区建立一个日期(2014 年 7 月 29 日上午 02:55:08)并得到这个异常:

I am trying to build a date (29/07/2014 at 02:55:08 am) in Casablanca timezone and got this exception:

线程main"中的异常 java.lang.IllegalArgumentException: HOUR_OF_DAY: 2 -> 3在 java.util.GregorianCalendar.computeTime(来源不明)

Exception in thread "main" java.lang.IllegalArgumentException: HOUR_OF_DAY: 2 -> 3 at java.util.GregorianCalendar.computeTime(Unknown Source)

Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("Africa/Casablanca"));
cal.setLenient(false);
cal.set(Calendar.DATE, 29);
cal.set(Calendar.MONTH, 6); // July
cal.set(Calendar.YEAR, 2014);
cal.set(Calendar.HOUR_OF_DAY, 2);
cal.set(Calendar.MINUTE, 55);
cal.set(Calendar.SECOND, 8);
cal.getTime();

使用 jre 1.7.0_71 和 1.8.0_20 引发异常,但不使用 1.6.0_30.

The exception is thrown with jre 1.7.0_71 and 1.8.0_20 , but not with 1.6.0_30.

据我所知,在那个特定时间没有发生夏令时变化.有什么想法吗?

As far as I know, there is no daylight saving change occuring at that particular time. Any idea ?

谢谢!

推荐答案

JRE 并不总是更新为最新的时区数据.要保持最新状态,您必须使用 TZUpdater 实用程序.Oracle 发布了两个 JRE 的时区更新列表和 TZUpdater.它表明最后一次 JRE 更新(在我撰写本文时)是针对 Java 7 的第 65 版和针对 Java 8 的第 11 版 - 它是使用 tzdata 的 2014c 版制作的.

The JRE is not always updated with the latest time zone data. To stay current, you must use the TZUpdater utility. Oracle publishes the list of time zone updates for both JRE and TZUpdater. It shows that the last JRE update (as of my writing this) was in release 65 for Java 7, and release 11 for Java 8 - and it was made with version 2014c of tzdata.

如果我们查看 2014c 版 tzdata 的来源,我们可以看到,当时对摩洛哥的猜测确实猜测了6月29日-7月29日的斋月夏令时暂停.

If we look at the sources for tzdata at version 2014c, we can see that the guess at that time for Morocco did indeed guess the Ramadan DST suspension from Jun 29 - Jul 29.

Rule    Morocco 2014    only    -   Jun  29      3:00   0       -
Rule    Morocco 2014    only    -   Jul  29      2:00   1:00    S

当然后来更新为 Chris 回答中显示的值,当时埃及最终宣布了实际日期.

It was of course later updated to the values shown in Chris's answer, when Egypt finally announced the real dates.

您可以在此处查看原始猜测中的一些面包屑 并且 tz 列表档案中有很多关于埃及的讨论,从 5 月开始,一直持续到 7 月.

You can see some of the breadcrumbs from the original guesswork here and there are many discussions in the tz list archives about Egypt, starting in May and continuing through to July.

这篇关于TimeZone casablanca (java) 的错误偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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