I have a "ddMMyy" template in my code that I specified using the appendValue methods:
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder() .appendValue(ChronoField.DAY_OF_MONTH, 2) .appendValue(ChronoField.MONTH_OF_YEAR, 2) .appendValue(ChronoField.YEAR_OF_ERA, 2) .toFormatter(); System.out.println(LocalDate.parse("100199", dateTimeFormatter));
However, this gives "0099" for the year:
0099-01-10
If I changed this to use appendPattern as follows:
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder() .appendPattern("ddMMyy") .toFormatter(); System.out.println(LocalDate.parse("100199", dateTimeFormatter));
I have the correct result for the year "2099" with a century in it.
2099-01-10
The code seems equivalent to me, why doesn't it produce the same result? Why is the first case missing a century?
java datetime java-8 java-time
Ivelina Georgieva
source share