Reputation: 1934
I had a piece of code that worked just fine and now somehow doesn't work.
I am reading in a csv file and get an error when reading in a time field of the format 4:38
.
My code that throws the exception is:
LocalTime.parse("4:38", DateTimeFormatter.ofPattern("HH:mm"))
I also tried "H:mm"
or "H:m"
for the pattern but it throws the same exception: Text '4:38' could not be parsed at index 0
. Any idea to why it throws an exception at the hour number?
I am using Java 8.
Upvotes: 6
Views: 2230
Reputation: 640
The pattern needs one single "H" and one single "m".
LocalTime.parse("4:38", DateTimeFormatter.ofPattern("H:m"));
It works fine for 4:38 and 14:38.
Official Doc: See "Patterns for Formatting and Parsing"
Upvotes: 10