以下代码片段
Instant.parse("2023-08-08T00:00:00+02:00")
按照 java-17 中的预期编译和执行。但是用java-8执行时,抛出以下异常
java.time.format.DateTimeParseException: Text '2023-08-01T00:00:00+02:00' could not be parsed at index 19
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.Instant.parse(Instant.java:395)
...
我的问题是为什么? java.time api 有什么变化吗?
请注意,我确实知道解决此问题的方法,以下代码适用于 java-8
OffsetDateTime.parse("2023-08-01T00:00:00+02:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME).toInstant()
它产生了期望的结果。我有兴趣知道在 java-time api 实现中,行为是否已经改变?