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?