1

I have a string which is supposed to be in ISO 8601 format. An example value of the string is:

"2017-01-12T07:12:15-0500"

I've been trying to parse this in a number of ways. I've tried both LocalDateTime and OffsetDateTime. All of these have failed:

OffsetDateTime ot = OffsetDateTime.parse("2017-01-12T07:12:15-0500");
OffsetDateTime ot = OffsetDateTime.parse("2017-01-12T07:12:15-0500", DateTimeFormatter.ISO_DATE_TIME);

LocalDateTime lt = LocalDateTime .parse("2017-01-12T07:12:15-0500");
LocalDateTime lt = LocalDateTime .parse("2017-01-12T07:12:15-0500", DateTimeFormatter.ISO_DATE_TIME);

The exception is always

Text '2017-01-12T07:12:15-0500' could not be parsed, unparsed text found at index 19

It seems to not like the 0500 part. I thought this was a valid format for an ISO 8601 date. If it's not, what's the proper way to parse this string?

SantiBailors
  • 1,596
  • 3
  • 21
  • 44
Michael Remijan
  • 687
  • 7
  • 22
  • 2
    Note that because you have hyphens and colons in the main part of your string, you should also have a colon in the offset `-05:00` to be strictly compliant with the ISO-8601 extended format. You can probably adjust the parsing code to accommodate, but it is not strictly compliant. ISO-8601 allows for basic and extended forms, but not to mix parts of each. – Matt Johnson-Pint Oct 10 '17 at 19:23

0 Answers0