How can I get with the TimeZone the Countryname

ぐ巨炮叔叔 提交于 2020-01-06 07:49:25

问题


I have the timezone. I have the city. How can I get the country?

Set<String> ids = DateTimeZone.getAvailableIDs();    

for (String id : ids) {
System.out.println(" "+id);

}

回答1:


There could be multiple countries per timezone, but if you want to print a list, I'd suggest putting them into a collection.. perhaps a two dimensional array.

http://www.timezoneconverter.com/cgi-bin/zonehelp.tzc

=======================

Based on your feedback and how your question changed, you should be able to use Google's Maps API, and do a Geocode webservice call to get the "CountryNameCode" node of the XML (or JSON object .. depending on the format you choose), and get your country code that way. Normally, this service is used to get latitude/longitude values (aka Geocoding) when you send an address as the arguments. Or it's used to get the address back (aka reverse Geocoding) if you send latitude/longitude arguments to the web service. But in your case, use Geocoding. You'll still get back the lat/long.. just ignore those values and parse the country from the response.




回答2:


You can get my time zone by the following statement

TimeZone germany = TimeZone.getTimeZone("Europe/Berlin");

See API for further documentation.

Please note, that some countries have different timeZones. (USA, Russia,... ) So you always need a location to refer to.



来源:https://stackoverflow.com/questions/6812249/how-can-i-get-with-the-timezone-the-countryname

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