问题
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