Issue with DateTimeParseException parameter when using STRICT recognizer style

I am trying to yyMMdd date string using the following pattern: yyMMdd and STRICT resolver as follows:

 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat).withResolverStyle(ResolverStyle.STRICT); LocalDate.parse(expiryDate, formatter); 

I get the following DateTimeParseException :

java.time.format.DateTimeParseException: text '160501' cannot be parsed: Failed to get LocalDate from TemporalAccessor: {YearOfEra = 2016, MonthOfYear = 5, DayOfMonth = 1}, ISO of type java.time.format.Parsed

When I go to the default resolution style, i.e. ResolverStyle.SMART , it allows dates like February 30th.

Can anybody help?

+2
source share
1 answer

A strict resolver requires an era to go with YearOfEra. Change your template to use "u" instead of "y" and it will work, i.e. "UuMMdd".

+4
source

Source: https://habr.com/ru/post/1261369/


All Articles