How do I format a javax.time.Instant as a string in the local time zone?

前端 未结 4 1994
迷失自我
迷失自我 2021-02-03 23:58

How do I format a javax.time.Instant as a string in the local time zone? The following translates a local Instant to UTC, not to the local time zone as I was expec

4条回答
  •  自闭症患者
    2021-02-04 00:47

    Why would you expect it to use the local time zone? You're explicitly asking for UTC:

    ZonedDateTime.ofInstant(instant, TimeZone.UTC)
    

    Just specify your local time zone instead:

    ZonedDateTime.ofInstant(instant, TimeZone.getDefault())
    

提交回复
热议问题