-1

I am trying to parse a simple DateTime with a different format. This line is just gibing me a hard time:

LocalDate.parse("Oct 11, 2021", DateTimeFormatter.ofPattern("MMM dd, yyyy"))

This is something trivial, why is it not working if I am providing the format?

Joe Almore
  • 4,036
  • 9
  • 52
  • 77

1 Answers1

3

The exception indicates your system language is not English1 (so Oct isn't a month name in the default locale). Specify the locale. Like,

LocalDate ld = LocalDate.parse("Oct 11, 2021",
        DateTimeFormatter.ofPattern("MMM dd, yyyy", Locale.US));
System.out.println(ld);

Outputs

2021-10-11

1Your original code worked for me, because my locale is English.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249