DateTimeFormmater
doesn't seem to handle single digit day of the month:
String format = "MM/dd/yyyy";
String date = "5/3/1969";
System.out.println(new SimpleDateFormat(format).parse(date));
System.out.println(LocalDate.parse(date, DateTimeFormatter.ofPattern(format)));
In this example, SimpleDateFormat
correctly parses the date, but DateTimeFormatter
throws an exception. If I were to use zero padded dates, e.g., "05/03/1969", both work. However, if either the day of month or the month of year are single digit, then DateTimeFormatter
throws an exception.
What is the right DateTimeFormatter
format to parse both one and two digit day of month and month of year?