I am currently getting this error and I really don't know why
java.time.format.DateTimeParseException: Text '21:5:20' could not be parsed at index 3
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.LocalTime.parse(LocalTime.java:441)
...
This is the method I use for parsing.
public static ZonedDateTime parse(String fecha, String pattern) {
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME;
LocalTime date = LocalTime.parse(fecha, formatter);
return ZonedDateTime.of(LocalDateTime.of(LocalDate.now(), date), ZoneId.systemDefault());
}
I need to return a ZonedDateTime
and therefore I'm doing what I'm doing.
The error says it seems to read the correct time from the file 21:5:20
, which looks valid, but for some reason it fails to parse it.
I really don't know what I'm doing wrong. Similar questions to this were referring to Dates, intead of Time.
I know this seems like a trivial problem, but I would honestly appreciate some help from the Java experts out here. Thank you in advance.