Get TimeZone offset value from TimeZone without TimeZone name

后端 未结 7 735
[愿得一人]
[愿得一人] 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:15

    I know this is old, but I figured I'd give my input. I had to do this for a project at work and this was my solution.

    I have a Building object that includes the Timezone using the TimeZone class and wanted to create zoneId and offset fields in a new class.

    So what I did was create:

    private String timeZoneId;
    private String timeZoneOffset;
    

    Then in the constructor I passed in the Building object and set these fields like so:

    this.timeZoneId = building.getTimeZone().getID();
    this.timeZoneOffset = building.getTimeZone().toZoneId().getId();
    

    So timeZoneId might equal something like "EST" And timeZoneOffset might equal something like "-05:00"

    I would like to not that you might not

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