Java Localtime parse exception
•
Java
I have a piece of code that works normally and now somehow doesn't work
I am reading a CSV file and an error occurred while reading in the time field in format 4:38
The code I threw the exception is:
LocalTime.parse("4:38",DateTimeFormatter.ofPattern("HH:mm"))
I also tried "H: mm" or "H: m" for the pattern, but it threw the same exception: the text '4:38' could not be resolved at index 0 Any idea why it throws an exception at the number of hours?
I use Java 8
Solution
This mode requires an "H" and an "m"
LocalTime.parse("4:38",DateTimeFormatter.ofPattern("H:m"));
It applies to 4:38 and 14:38
Official doc: see "modes of formatting and analysis"
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码