0

Parsing date string using DateTimeFormatter fails at blank space. Can someone point out what am I missing?

String dateStr = "10/10/2015 4:00:00 PM"
LocalDateTime.parse(date, DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a", Locale.US));

java.time.format.DateTimeParseException: Text '10/10/2015 4:00:00 PM' could not be parsed at index 11
java_dude
  • 4,038
  • 9
  • 36
  • 61

1 Answers1

2

It failed because the format of the input string is not yet correct. If you want hh:mm:ss, you need to have your input as 04:00:00 - with the hour as 04 to match hh.

Dat Nguyen
  • 1,626
  • 22
  • 25