Error in Conversion of String format to Date format

Hi @PKRISH , please note that the case is important. You need to be careful to use the examples as they were given. So the year yyyy remains lower case.

i.e. the format is:

dd-MM-yyyy
or
d-M-yyyy
(or variations of those)

The single d and single M allow for day and month both as single digit, or double digit or with leading zero. If you specify dd or MM it only matches where the day / month is represented as 2 digits. i.e. d and M are less restrictive than dd and MM

It’s not entirely obvious at first glance, but you get used to it.

The list of formats are those defined for java, and can be viewed here
DateTimeFormatter (Java Platform SE 8 ) (oracle.com)

2 Likes