When using DateTimeFormatter
of format "yyMMdd"
, strange things happen... LocaleDate.of(0,1,5)
is formatted to "010105"
, but "000105" is correctly parsed to LocalDate.of(2015, 1, 5)
. Why is that??
For testing:
@Test
public void testYear2000() {
LocalDate localDate = LocalDate.of(0, 1, 5);
String format = DateTimeFormatter.ofPattern("yyMMdd").format(localDate);
assertThat(format, is("000105")); // fail! it is "010105"
LocalDate parse = LocalDate.parse("000105", DateTimeFormatter.ofPattern("yyMMdd"));
assertThat(parse, is(LocalDate.of(2000, 1, 5))); //pass
}