0

I have this code fragment which worked previously for half year ( I wrote it myself ).

Yesterday I received new laptop with windows 10 ( previously 8.1 ) installed the most recent Java JDK jdk1.8.0_181 and this code stopped working with error.

Is it something I was missing for the whole time or there were some changes in java internal API ?

How I can fix it ? I believe it was written properly.

Caused by: java.time.format.DateTimeParseException: Text '29-Apr-2010,13:00:14' could not be parsed at index 3


private static final DateTimeFormatter PP_FORMATTER = DateTimeFormatter.ofPattern("d-MMM-yyyy,HH:mm:ss");
private static final LocalDate DATE = LocalDate.parse("29-Apr-2010,13:00:14", PP_FORMATTER);
ashur
  • 4,177
  • 14
  • 53
  • 85
  • 1
    " installed the most recent Java JDK `jdk1.8.0_181`" That is not the most recent JDK. – Andy Turner Sep 12 '18 at 08:55
  • 1
    Something like `DateTimeFormatter PP_FORMATTER = DateTimeFormatter.ofPattern("d-MMM-yyyy,HH:mm:ss", Locale.UK)` will fix the problem, as to why it's changed, I don't know - but it's probably good practice anyway – MadProgrammer Sep 12 '18 at 08:56
  • 1
    @AndyTurner Obviously I was pointing to the most recent update to JDK 8, this is why I provided the version. It is the most recent version on oracle website. – ashur Sep 12 '18 at 09:01
  • 2
    Maybe new OS was installed with different default locale? – Ivan Sep 12 '18 at 09:09
  • @Ivan Yes, exactly that, the default locale were changed, bringing back Locale to US and all formats resolved the issue – ashur Sep 12 '18 at 09:29

1 Answers1

0

try to add Locale.US

private static final DateTimeFormatter PP_FORMATTER = DateTimeFormatter.ofPattern("d-MMM-yyyy,HH:mm:ss", Locale.US);

otherwise, you maybe able to parse only numeric format for the month.

vnkid
  • 308
  • 2
  • 11