ThreeTen / threetenbp

Backport of functionality based on JSR-310 to Java SE 6 and 7. This is NOT an implementation of JSR-310.

Home Page:http://www.threeten.org/threetenbp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parse Error DateTimeParseException

Morons opened this issue · comments

I am passing a String 2021-07-31T00:00:00 [DateTimeFormatter.ISO_LOCAL_DATE_TIME] Not expecting this Error!

org.threeten.bp.format.DateTimeParseException: Text '2021-07-31T00:00:00' could not be parsed: Unable to obtain Instant from TemporalAccessor: DateTimeBuilder[, ISO, null, 2021-07-31, 00:00], type org.threeten.bp.format.DateTimeBuilder

Parsing with DateTimeFormatter.ISO_LOCAL_DATE_TIME yields a result that has no timezone information. Therefore, it cannot be directly converted into an Instant, which represents a specific point in time. You must add timezone information, for example:

LocalDateTime localDateTime = LocalDateTime.parse("2021-07-31T00:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
ZonedDateTime dateTime = localDateTime.atZone(ZoneOffset.UTC);
Instant instant = dateTime.toInstant();

Yes Thanx I saw It worked by Adding Z, however fixing dates by adding "Text" Pieces in NEVER a good idea