0

I am looking for the code that displays list of countries/regions in android and by selecting a specific country/region, it displays the time zone of it. for example when i choose "central America" as country/region then it should displays "UTC-06:00" as Time Zone. so i want to know if Android provide this functionality by default or i am to list down all countries/regions in an array and Time zones in another array and make the logic.

i have used the following code but no success

DateFormat format = new SimpleDateFormat("MMMMM d, yyyy, h:mm a");
TimeZone utc = TimeZone.getTimeZone("Central America");
System.out.println(utc.getID());
Log.d("Time", utc.getID());
GregorianCalendar gc = new GregorianCalendar(utc);
Date now = gc.getTime();
System.out.println(format.format(now));
Log.d("Time", format.format(now));
isaias-b
  • 2,255
  • 2
  • 25
  • 38
user3124780
  • 83
  • 1
  • 9
  • Many countries have multiple time zones, so you won't be able to get a single time zone back if you're filtering by country/region. Do you want a list back? Or do you want the single time zone that applies to a particular location (by longitude and latitude coordinates)? – Matt Johnson-Pint Jun 22 '14 at 17:13
  • Google provides an API for that..Check this [Google Time Zone](https://developers.google.com/maps/documentation/timezone/) – Lal Jun 22 '14 at 17:16
  • Check this [link](http://stackoverflow.com/questions/41504/timezone-lookup-from-latitude-longitude) tooo – Lal Jun 22 '14 at 17:19
  • 2
    @Lal - The main list is [here](http://stackoverflow.com/q/16086962/634824). But I'm awaiting the OP's answer to whether that's what is needed or not. – Matt Johnson-Pint Jun 22 '14 at 17:20
  • @user3124780 - Context would help also. Are you trying to find the time zone for a particular location? Or are you building a UI for a time zone picker for a more advanced scenario? Or something else? – Matt Johnson-Pint Jun 22 '14 at 17:28
  • Thanks everyone for the time given. I simply want to show list of all the regions like "Islamabad, karachi", "tashkent" etc. and when user chooses a region from the provided list then it displays its Timezone/code. for example for Islamabad, TimeZone/code is UTC+05:00. – user3124780 Jun 22 '14 at 19:03
  • And what kind of values would be in this list? All the cities of the world? Specific countries? What would you do for [Russia](http://en.wikipedia.org/wiki/Time_in_Russia) or [Australia](http://en.wikipedia.org/wiki/Time_in_Australia) or [the USA](http://en.wikipedia.org/wiki/Time_in_USA)? Also, recognize that a time zone is not the same thing as a time zone offset. Islamabad may always be at UTC+05:00, but Paris alternates between UTC+01:00 and UTC+02:00. See "Time zone != Offset" in [the timezone tag wiki](http://stackoverflow.com/tags/timezone/info). – Matt Johnson-Pint Jun 22 '14 at 19:16

0 Answers0