I have the following string: String timeStamp = "2020-01-31 12:13:14 +03:00"
.
And I tried to parse it using Java 8 DateTimeFormatter.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( format );
tmpTimestamp = ZonedDateTime.parse( timeStamp, formatter );
where format
is one of:
"yyyy-MM-dd' 'HH:mm:ss' 'Z",
"yyyy-MM-dd' 'HH:mm:ss' 'X",
"yyyy-MM-dd' 'HH:mm:ss' 'x",
"yyyy-MM-dd HH:mm:ss Z",
"yyyy-MM-dd HH:mm:ss X",
"yyyy-MM-dd HH:mm:ss x",
None is working. Always I got DateTimeParseException
either pointing to '+' or to ':' character in offset substring "+03:00"
According to JavaDocs: Class DateTimeFormatter "+03:00" shall be supported by any of: Z
, X
and x
.
So the question is how to construct formatter string to parse it?
LocalDateTime
, but ratherOffsetDateTime
(since it has an offset). – Rathskeller