How can I get with the TimeZone the Countryname
I have the timezone. I have the city. How can I get the country?
Set<String>开发者_StackOverflow社区 ids = DateTimeZone.getAvailableIDs();
for (String id : ids) {
System.out.println(" "+id);
}
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.
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.
精彩评论