This code
String formattedDate = OffsetDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE);
OffsetDateTime.parse(formattedDate, DateTimeFormatter.ISO_OFFSET_DATE);
leads to
java.time.format.DateTimeParseException: Text '2020-11-27+01:00' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {OffsetSeconds=3600},ISO resolved to 2020-11-27 of type java.time.format.Parsed
Shouldn't this work?
As the name suggests,
OffsetDateTime
needs time components (hour, minute etc.) as well.DateTimeFormatter.ISO_OFFSET_DATE
does not have pattern for time components and therefore you should not use it to parse a date string intoOffsetDateTime
. You can build a formatter with default time components.Output: