ISO Starndard Date Format implementation consistency on DateTimeFormatter and String.format
Roger Riggs
roger.riggs at oracle.com
Mon Oct 9 16:04:58 UTC 2023
Hi,
Java.time has a clear definition of negative years.
It would need a closer look as to j.u.Formatter's interpretation of
negative years, though it should be consistent for j.t.LocalDate.
Created:
8317742 <https://bugs.openjdk.org/browse/JDK-8317742> ISO Starndard Date
Format implementation consistency on DateTimeFormatter and String.format
Regards, Roger
On 10/4/23 10:22 AM, 温绍锦(高铁) wrote:
> 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?
>
> - wenshao
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231009/e485a442/attachment.htm>
More information about the core-libs-dev
mailing list