您看到的问题是由于在两个版本的Java中使用了time zone database的差异.时区规则会随着时间的推移而更新,而您遇到的旧日期在新规则下会得到不同的处理.
对于我的机器上的Java版本,我得到的Java 11 17的
具体原因是2020D&Amp;2021E目前在欧洲/阿姆斯特丹的区域偏移量为+01:19:32.另一方面,2023c在欧洲/阿姆斯特丹的区域偏移量为+01:00.将1:19:32与1934-07-21T22:40:28Z相加得到第二天的午夜(1934-07-22),但将1:00:00相加得到同一天的23:40:28(1934-07-21).
Time zone database change
我在互联网上做了一些调查,根据time zone database mailing list,这一更改似乎是在时区数据库版本2022b中进行的.因此,2022A和更早版本使用+01:19:32偏移,2022B和更高版本使用+01:00偏移.
2022年合并了阿姆斯特丹和布鲁塞尔的时区,这两个时区在1970年后是相同的,但在足够早的历史日期上有所不同.看起来阿姆斯特丹一度用了local mean time,因此出现了奇怪的偏移量.然而,布鲁塞尔似乎并没有这么做.
Between 2022a an b the timezone info for Europe/Amstedam is removed:
Z Europe/Amsterdam 0:19:32 - LMT 1835
The timezone info for Brussels around that date differs from Amsterdams timezone info.
在我的Linux系统上,用python确定该时间段附近日期的时区信息,自最近一次更新以来,返回了0分钟的偏移量,而不是之前的19分钟.
删除此时区信息是故意的还是错误的?
维护商使用布鲁塞尔针对阿姆斯特丹的规则合并了阿姆斯特丹和布鲁塞尔的时区信息,因为自1970年以来,默认数据包中的规则没有任何不同.这抹go 了1970年之前阿姆斯特丹的规则,包括当地标准时间.
Demonstration
String javaVersion = System.getProperty("java.vendor") + Runtime.version();
String timeZoneDatabase = ZoneRulesProvider.getVersions("UTC")
.keySet().stream().findFirst().orElseThrow();
Date date = new Date(-1118625572000L);
ZoneId timeZone = ZoneId.of("Europe/Amsterdam");
ZonedDateTime zonedDateTime = date.toInstant().atZone(timeZone);
LocalDate localDate = zonedDateTime.toLocalDate();
System.out.printf("Java: %s%n", javaVersion);
System.out.printf("Time Zone Database: %s%n", timeZoneDatabase);
System.out.printf("Instant (UTC): %s%n", date.toInstant());
System.out.printf("LocalDate (Europe/Amsterdam): %s%n", localDate);
System.out.printf("Time zone offset: %s%n", zonedDateTime.getOffset());
输出
Java: AdoptOpenJDK11.0.10+9
Time Zone Database: 2020d
Instant (UTC): 1934-07-21T22:40:28Z
LocalDate (Europe/Amsterdam): 1934-07-22
Time zone offset: +01:19:32
Java: Eclipse Adoptium17.0.2+8
Time Zone Database: 2021e
Instant (UTC): 1934-07-21T22:40:28Z
LocalDate (Europe/Amsterdam): 1934-07-22
Time zone offset: +01:19:32
Java: Eclipse Adoptium21.0.1+12-LTS
Time Zone Database: 2023c
Instant (UTC): 1934-07-21T22:40:28Z
LocalDate (Europe/Amsterdam): 1934-07-21
Time zone offset: +01:00