I have a date formatted in the following way :
The year in four digits then the week number in two digits.
For instance, the fourth week of 2018 will be 201804.
I'm having trouble parsing these dates using Java 8's LocalDate and DateTimeFormatterBuilder.
Here is how I try to parse the date :
LocalDate.parse(
"201804",
new DateTimeFormatterBuilder().appendPattern("YYYYww").parseDefaulting(WeekFields.ISO.dayOfWeek(), 1).toFormatter()
);
The execution throws the following exception :
java.time.format.DateTimeParseException: Text '201804' could not be parsed at index 0
The odd behavior is that, when I add a separator between the date parts, the exception is not thrown anymore :
LocalDate.parse(
"2018 04",
new DateTimeFormatterBuilder().appendPattern("YYYY ww").parseDefaulting(WeekFields.ISO.dayOfWeek(), 1).toFormatter()
);
Results in :
2018-01-22
Is there a thing I am missing with the formatter ?