1

I have this piece of code:

public static final String DATE_PATTERN = "yyyy-MM-dd";

    OffsetDateTime.parse(startTime, DateTimeFormatter.ofPattern(DateFormat.DATE_PATTERN)

But I have this error when parsing:

java.time.format.DateTimeParseException: Text '2019-07-10' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2019-07-10 of type java.time.format.Parsed
Nunyet de Can Calçada
  • 4,171
  • 41
  • 153
  • 252

2 Answers2

2

ZonedDateTime

A date-time with a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00 Europe/Paris.

LocalDate

A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.

Since your string just represents simple date, so use LocalDate

LocalDate date = LocalDate.parse(startTime, DateTimeFormatter.ISO_DATE);
Deadpool
  • 33,221
  • 11
  • 51
  • 91
1

The problem is that these parse methods need the offset string part (+/-hh:mm), if you want to use OffsetDateTime you need to add that part, here some examples:

OffsetDateTime date = OffsetDateTime.parse("2016-10-02T20:15:30+01:00",
                DateTimeFormatter.ISO_DATE_TIME);

If you just want that format, "yyyy-mm-dd" you just need to go with traditional LocalDate.parse

Damian Lattenero
  • 15,181
  • 3
  • 34
  • 70