Ява 8 здесь. У меня есть следующий код:
final String createdDateStr = "20110920";
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYYMMdd");
final LocalDate localDate = LocalDate.parse(createdDateStr, formatter);
Во время выполнения я получаю следующее исключение:
java.time.format.DateTimeParseException: Text '20110920' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.
...выбрасывается из вызова LocalDate.parse(...)
. Что не так с парсером?!
Exception in thread "main" java.time.format.DateTimeParseException: Text '20110920' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {MonthOfYear=9, WeekBasedYear[WeekFields[SUNDAY,1]]=2011, DayOfMonth=20},ISO of type java.time.format.Parsed
WeekBasedYear подсказывает, что формат неверен. ОП хотел y, но написал Y. Вероятно, распространенная ошибка. :) - person Ray Toal   schedule 20.09.2018