2

Following code does not work:

DateTimeFormatter.ofPattern("L dd, yyyy", Locale.US).parse("December 15, 2009");

as it throws

java.time.format.DateTimeParseException: Text 'December 15, 2009' could not be parsed at index 0

How to make it work? Is it even possible using provided Locale?? (without using additional Map that maps String to month number.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99

1 Answers1

4

use MMMM instead of L:

DateTimeFormatter.ofPattern("MMMM dd, yyyy", Locale.US).parse("December 15, 2009")

I find the javadoc there a little bit confusing. I also marked this one as duplicate to DateTimeFormatter month pattern letter "L" fails as it deals mostly with the same issue.

Community
  • 1
  • 1
Roland
  • 22,259
  • 4
  • 57
  • 84
  • Strange that it fails, since according to `DateTimeFormatterBuilder` sources, both `M` and `L` denote the same `ChronoField.MONTH_OF_YEAR`. – M. Prokhorov Feb 01 '17 at 16:35