I am trying to convert date 06-12-2015 02:10:10 PM
from default zone to UTC using ZonedDateTime
.
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
ZonedDateTime utc = ZonedDateTime.of(localDateTime, ZoneOffset.UTC);
but utc
returns 2015-12-06T14:10:10Z
instead of 06-12-2015 09:10:10 AM
How can I convert date from default zone to UTC? The answer given here convert current time to UTC.
You can use
ZonedDateTime.ofInstant(Instant, ZoneId)
where the second parameter isUTC
(the instant knows the local offset). Something like,And I get (corresponding to my local zone offset)