我在使用 . 测试一些时区时发现了一个奇怪的 java 差异ZonedDateTime。我试图解析 1970 年之前的日期,发现结果在 java 版本之间发生变化。1932 年荷兰的偏移量是+00:19。有谁知道为什么会发生这种情况?我觉得这可能与时区数据库项目( https://github.com/eggert/tz )中欧洲时区的捆绑有关,但我不确定。有没有办法获得java中的旧行为?就像设置一样?
ZonedDateTime zdt = LocalDateTime.parse("1932-10-20T10:19:32.000").atZone(ZoneId.of("Europe/Amsterdam"));
System.out.println(zdt);
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.append(ISO_LOCAL_DATE)
.appendLiteral('T')
.appendValue(HOUR_OF_DAY, 2)
.appendLiteral(':')
.appendValue(MINUTE_OF_HOUR, 2)
.optionalStart()
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.optionalStart()
.appendFraction(NANO_OF_SECOND, 3, 3, true)
.appendOffset("+HH:MM", "Z")
.toFormatter();
System.out.println(formatter.format(zdt));
System.out.println(
java.time.zone.ZoneRulesProvider
.getVersions("UTC")
.lastEntry()
.getKey()
);
Run Code Online (Sandbox Code Playgroud)
结果 Temurin (java jdk) 11.0.16 (预期输出),最后一行显示时区数据库版本:
1932-10-20T10:19:32+00:19:32[Europe/Amsterdam]
1932-10-20T10:19:32.000+00:19
2022a
Run Code Online (Sandbox Code Playgroud)
Temurin 11.0.17 的结果:
1932-10-20T10:19:32Z[Europe/Amsterdam]
1932-10-20T10:19:32.000Z
2022c
Run Code Online (Sandbox Code Playgroud)
编辑:从 17.0.5 开始,JDK 17 中也存在一个问题:
铁木林 17.0.4:
1932-10-20T10:19:32+00:19:32[Europe/Amsterdam]
1932-10-20T10:19:32.000+00:19
2022a
Run Code Online (Sandbox Code Playgroud)
铁木林 …