How to get timezone from timezone offset in java?

倖福魔咒の 提交于 2019-12-18 09:04:11

问题


I know how to get the opposite. That is given a timezone I can get the timezone offset by the following code snippet:

TimeZone tz = TimeZone.getDefault();
System.out.println(tz.getOffset(System.currentTimeMillis()));

I want to know how to get the timezone name from timezone offset.

Given,

timezone offset = 21600000 (in milliseconds; +6.00 offset)

I want to get result any of the following possible timezone names:

(GMT+6:00) Antarctica/Vostok
(GMT+6:00) Asia/Almaty
(GMT+6:00) Asia/Bishkek
(GMT+6:00) Asia/Dacca
(GMT+6:00) Asia/Dhaka
(GMT+6:00) Asia/Qyzylorda
(GMT+6:00) Asia/Thimbu
(GMT+6:00) Asia/Thimphu
(GMT+6:00) Asia/Yekaterinburg
(GMT+6:00) BST
(GMT+6:00) Etc/GMT-6
(GMT+6:00) Indian/Chagos

回答1:


Use getAvailableIDs() of TimeZone class

import java.util.*;
class hello
{
   public static void main (String[] args) throws java.lang.Exception
   {
     TimeZone tz=TimeZone.getDefault();
     String a[]=tz.getAvailableIDs(21600000);
     for(int i=0;i<a.length;i++)
      System.out.println(a[i]);
  }
}


来源:https://stackoverflow.com/questions/37184908/how-to-get-timezone-from-timezone-offset-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!