Parse error LocalDateTime: DateTimeParseException
When I try to parse the string "2017-04-06T21: 35: 00Z" as LocalDateTime, I get the below exception:
java.time.format.DateTimeParseException: Text '2017-04-06T21:35:00Z' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {InstantSeconds=1491514500, MicroOfSecond=0, MilliOfSecond=0, NanoOfSecond=0},ISO of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920) ~[na:1.8.0_91]
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855) ~[na:1.8.0_91]
at java.time.LocalDateTime.parse(LocalDateTime.java:492) ~[na:1.8.0_91]
And this is how I parse this line:
private static DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
LocalDateTime time = LocalDateTime.parse("2017-04-06T21:35:00Z", formatter);
Of course, I can parse this string without using the ISO_INSTANT format, but it looks like I can also parse this string using ISO_INSTANT because of the following documentation:
* The ISO instant formatter that formats or parses an instant in UTC,
* such as '2011-12-03T10:15:30Z'.
* <p>
* This returns an immutable formatter capable of formatting and parsing
* the ISO-8601 instant format.
* When formatting, the second-of-minute is always output.
* The nano-of-second outputs zero, three, six or nine digits digits as necessary.
* When parsing, time to at least the seconds field is required.
* Fractional seconds from zero to nine are parsed.
* The localized decimal style is not used.
It looks to me like the string is exactly the same in ISO_INSTANT format. This is why I am wondering if the code is not working.
Sincerely.
+3
Fırat Çağlar Akbulut
source
to share
1 answer
The first answer here seems to be what you are looking for.
Didn't have enough reputation to comment ...
+2
Robin topper
source
to share