4

I'm trying to create a LocalDate object:

LocalDate date = LocalDate.parse(
    "1. juli 2014", 
    DateTimeFormatter.ofPattern("d. LLLL YYYY", new Locale("nb", "NO"));

But I get an exception:

java.time.format.DateTimeParseException: Text '1. juli 2014' could not be parsed: 
    Unable to obtain LocalDate from TemporalAccessor: 
    {WeekBasedYear[WeekFields[MONDAY,4]]=2014, MonthOfYear=7, DayOfMonth=1},
    ISO of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1919)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1854)
at java.time.LocalDate.parse(LocalDate.java:400)

The exception seems to indicate that the correct data is in there ("juli" is Norwegian and is month number 7).

neu242
  • 15,796
  • 20
  • 79
  • 114

1 Answers1

5

So, I found the solution, even though this probably is a Java 8 bug, as @NimChimpsky commented on.

By using "d. LLLL yyyy" (with year-of-era) instead of "d. LLLL YYYY" (with week-based-year), the parsing works as intended.

Community
  • 1
  • 1
neu242
  • 15,796
  • 20
  • 79
  • 114