Getting the current Instant in a specific TimeZone

后端 未结 1 1161
梦如初夏
梦如初夏 2021-01-05 09:08

I have tried to get the current Instance on a specific timeZone but it does not work as expected. Any idea on how to do this ?

Here is what i did:

I         


        
1条回答
  •  孤街浪徒
    2021-01-05 09:39

    Instant are not Timezone aware. If you need a time zone aware timestamp, you should use ZonedDateTime.

    Check out ZonedDateTime.now(timezone) which will use the provided timezone. To use the machine's default timezone, use ZonedDateTime.now()

    If you want to parse a ZonedDateTime and override the timezone, you can use ZonedDateTime.withZoneSameLocal or ZonedDateTime.withZoneSameInstant depending on your need.

    0 讨论(0)
提交回复
热议问题