下面的代码片段在Java 8中运行时没有错误.但是,当我在Java 17中运行相同的代码时,它失败了.
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
public class Main2 {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH[:mm[:ss[.SSS]]]X");
OffsetDateTime offSetDateTime = OffsetDateTime.parse("2021-10-09T08:59:00.00Z", formatter);
System.out.println(offSetDateTime);
}
}
在Java 17上运行时的输出:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2021-10-09T08:59:00.00Z' could not be parsed at index 19
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954)
at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:404)
at Main2.main(Main2.java:9)
但是,如果我对Java 8运行相同的代码,它会产生以下结果:
2021-10-09T08:59Z
如果我将测试数据从"2021-10-09T08:59:00.00Z"
更改为"2021-10-09T08:59:00.000Z"
,它在Java 17中可以工作.你知道Java 17中的哪些更改导致它失败吗?