If you try to parse a String to a LocalDate with the parse method, you have to be carefull because the default ResolverStyle in the DateTimeFormater, when you call the .ofPattern() method, is SMART. Sounds funny, it is :).
Here are some examples what you should expect:
LENIENT – Style to resolve dates and times leniently.
2019-02-27 - is parsed to - 2019-02-27
2019-02-28 - is parsed to - 2019-02-28
2019-02-29 - is parsed to - 2019-03-01 //Date moved to next month
SMART – Style to resolve dates and times in a smart, or intelligent, manner.
2019-02-27 - is parsed to - 2019-02-27
2019-02-28 - is parsed to - 2019-02-28
2019-02-29 - is parsed to - 2019-02-28 //Date adjusted based on smart guessing
STRICT – Style to resolve dates and times strictly.
2019-02-27 - is parsed to - 2019-02-27
2019-02-28 - is parsed to - 2019-02-28
2019-02-29 - is parsed to - //java.time.format.DateTimeParseException
For STRICT you have to use [uuuu] instead of [yyyy] for years.
Subscribe to our newsletter
Get the latest posts delivered right to your inbox.