0

我想知道提供的时区 ID 的大陆/国家名称?例如

System.out.println(TimeZone.getTimeZone("PDT"));

I wanted answer as north america/america. 

System.out.println(TimeZone.getTimeZone("GMT+05:30"));

I wanted answer as asia/india.

i am not getting the desired output.

The reason of asking question :: I am storing in my database on server the timezone(PDT,GMT+05:30) as given by the mobile    
device.Now i need to perform analytics , that my app was  accessed from which continent/country.

帮助表示赞赏...

4

2 回答 2

5

不。时区在全球范围内垂直切割,并且有许多国家共享相同的时区。

例如,印度位于中国西南部,因此“中国”的答案对于某些时区同样正确。

有关时区及其适用于哪些国家/地区的地图,请参阅此网站:http ://www.timeanddate.com/time/map/

于 2013-09-24T13:43:45.560 回答
3

如果您想向后计算,这可能会有所帮助......一些时区包含一些您正在寻找的信息,例如,尝试:

 for (String s : TimeZone.getAvailableIDs()) {
            System.out.println(s);
 }

输出如下..

...
Europe/Amsterdam
Europe/Andorra
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Budapest
Europe/Copenhagen
Europe/Gibraltar
Europe/Ljubljana
Europe/Luxembourg
Europe/Madrid
Europe/Malta
Europe/Monaco
Europe/Oslo
Europe/Paris
...

您可以使用它来获取 TimeZones 并检查它们所拥有的信息,尽管需要做很多工作,您也许可以获得您想要的东西。

System.out.println(TimeZone.getTimeZone("Europe/Amsterdam"));
System.out.println(TimeZone.getTimeZone("UTC"));

输出

sun.util.calendar.ZoneInfo[id="Europe/Amsterdam",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=180,lastRule=java.util.SimpleTimeZone[id=Europe/Amsterdam,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

使用偏移量,您可以计算出与 UTC 时间的关系。即使在您不考虑夏令时等的简单情况下,这也是非常复杂、棘手且耗时的。可能,我会说。

于 2013-09-24T13:48:49.130 回答