Get TimeZone offset value from TimeZone without TimeZone name

后端 未结 7 823
[愿得一人]
[愿得一人] 2020-12-02 10:22

I need to save the phone\'s timezone in the format [+/-]hh:mm

I am using TimeZone class to deal with this, but the only format I can get is the following:

         


        
7条回答
  •  一生所求
    2020-12-02 11:06

    With java8 now, you can use

    Integer offset  = ZonedDateTime.now().getOffset().getTotalSeconds();
    

    to get the current system time offset from UTC. Then you can convert it to any format you want. Found it useful for my case. Example : https://docs.oracle.com/javase/tutorial/datetime/iso/timezones.html

提交回复
热议问题