I am trying for hours now to parse this String to LocalDate and I just can't find where my pattern is wrong.
public void parseDate() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd'-'MMM'-'yy");
LocalDate date = LocalDate.parse("05-Sep-20", formatter);
}
I get the following exception:
java.time.format.DateTimeParseException: Text '05-Sep-20' could not be parsed at index 3
It works fine when using the pattern dd'-'MMMM'-'yy
or dd'-'MM'-'yy
, but it just won't work for MMM
I used the single quotes around the dash, because otherwise I was getting a parsing exception at a different index.
I am using Java1.8 and java.time