I have a XML element with the following content:
<lastModified>2019-10-09T19:20:45.677+02:00</lastModified>
This is mapped to Java's XMLGregorianCalendar.
I need to convert this value in an appropriate java.time instance.
I am a little confused about which java.time class is the "correct" (i.e. lossless) representation of this XMLGregorianCalendar value.
I suppose it should be ZonedDateTime or is OffsetDateTime the better choice?
The
Stringyou have ("2019-10-09T19:20:45.677+02:00") is in an ISO format that doesn't even need an extra formatter in order to parse it. The main reason for the use of anOffsetDateTimeare the last 6 characters:+02:00, which denote an offset of 2 hours from UTC (more than just one time zone may actually have this offset at the same time).You can convert this value into the proper
java.timeinstance like this, for example:Output:
This should be correct (lossless enough by losing no information).