The following code snippet runs without error in Java 8. However, when I run the same code in Java 17 it fails.
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);
}
}
Output when run on 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)
However, if I run the same code against Java 8 it gives the following result:
2021-10-09T08:59Z
If I change the test data from "2021-10-09T08:59:00.00Z"
to "2021-10-09T08:59:00.000Z"
, it works in Java 17. Any idea what changes in Java 17 has causes it it fail?
S
it works for me – Neolith