ZonedDateTime to UTC with offset applied?

前端 未结 4 685
不知归路
不知归路 2020-12-31 16:31

I am using Java 8
This is what my ZonedDateTime looks like

2013-07-10T02:52:49+12:00

I get this value as <

4条回答
  •  太阳男子
    2020-12-31 17:14

    It looks like you need to convert to the desired time zone (UTC) before sending it to the formatter.

    z1.withZoneSameInstant( ZoneId.of("UTC") )
      .format( DateTimeFormatter.ISO_OFFSET_DATE_TIME )
    

    should give you something like 2018-08-28T17:41:38.213Z

提交回复
热议问题