j.t.DateTimeFormatter defines ISO_LOCAL_DATE, j.u.Formatter.DateTime also defines ISO_STANDARD_DATE ("%tF"), and now their behavior is different outside the range of [0,9999], We run the following code and we can see their different behaviors:
```java
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
int[] years = {-99999, -9999, -999, -99, -9, 0, 9, 99, 999, 1999, 2999, 9999, 99999};
for (int year : years) {
LocalDate localDate = LocalDate.of(year, 1, 1);
System.out.println(formatter.format(localDate) + "\t\t->\t\t" + "%tF".formatted(localDate));
}
```
* output
```
-99999-01-01 -> 100000-01-01
-9999-01-01 -> 10000-01-01
-0999-01-01 -> 1000-01-01
-0099-01-01 -> 0100-01-01
-0009-01-01 -> 0010-01-01
0000-01-01 -> 0001-01-01
0009-01-01 -> 0009-01-01
0099-01-01 -> 0099-01-01
0999-01-01 -> 0999-01-01
1999-01-01 -> 1999-01-01
2999-01-01 -> 2999-01-01
9999-01-01 -> 9999-01-01
+99999-01-01 -> 99999-01-01
```
Should we keep it consistent?
OpenJDK core-libs-dev:
https://mail.openjdk.org/pipermail/core-libs-dev/2023-October/112892.html
```java
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
int[] years = {-99999, -9999, -999, -99, -9, 0, 9, 99, 999, 1999, 2999, 9999, 99999};
for (int year : years) {
LocalDate localDate = LocalDate.of(year, 1, 1);
System.out.println(formatter.format(localDate) + "\t\t->\t\t" + "%tF".formatted(localDate));
}
```
* output
```
-99999-01-01 -> 100000-01-01
-9999-01-01 -> 10000-01-01
-0999-01-01 -> 1000-01-01
-0099-01-01 -> 0100-01-01
-0009-01-01 -> 0010-01-01
0000-01-01 -> 0001-01-01
0009-01-01 -> 0009-01-01
0099-01-01 -> 0099-01-01
0999-01-01 -> 0999-01-01
1999-01-01 -> 1999-01-01
2999-01-01 -> 2999-01-01
9999-01-01 -> 9999-01-01
+99999-01-01 -> 99999-01-01
```
Should we keep it consistent?
OpenJDK core-libs-dev:
https://mail.openjdk.org/pipermail/core-libs-dev/2023-October/112892.html
- csr for
-
JDK-8317752 ISO Standard Date Format implementation consistency on DateTimeFormatter and String.format
-
- Closed
-