Reputation: 1891
The ZonedDateTime
currently in
`2020-06-07T14:10:00+01:00`
The format the ZonedDateTime
that I am looking for
2020-06-07T13:10:24Z
Upvotes: 0
Views: 338
Reputation: 40024
Try the following:
String time = "2020-06-07T14:10:00+01:00";
Desired output format = 2020-06-07T13:10:24Z
ZonedDateTime zdt = ZonedDateTime.parse(time,
DateTimeFormatter.ISO_ZONED_DATE_TIME);
System.out.println(zdt.format(DateTimeFormatter.ISO_INSTANT));
Prints
2020-06-07T13:10:00Z
Upvotes: 0
Reputation: 1536
You can do it like this:
ZonedDateTime.parse("2020-06-07T14:10:00+01:00").toInstant()
Or if you must have a ZonedDateTime
:
ZonedDateTime.parse("2020-06-07T14:10:00+01:00").withZoneSameInstant(ZoneOffset.UTC);
Upvotes: 2