I've parse a date like: 2016-07-21T09:24:06Z on UTC zone.
I change it to Instant
:
Instant.parse(stringLiteral) -> 2016-07-21T09:24:06Z
Then to java.util.Date
:
Date utcDateTime = Date.from(Instant.parse(stringLiteral));
However, utcDateTime
is Thu Jul 21 11:24:06 CEST 2016
.
How can I to keep the UTC zone and create a java.util.Date
object on UTC?
I'd like to use an elegant way to do that without specifying the parse format string.
I've also tried with this code:
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date utcDateTime = isoFormat.parse(stringLiteral);
However, the datetime is changed as well -> Thu Jul 21 11:24:06 CEST 2016