Android default timezone list

I was wondering if I can get the default code for the timezone select list for version 2.3.3 for Android?

enter image description here

enter image description here

+6
source share
2 answers
String[] ids=TimeZone.getAvailableIDs(); for(int i=0;i<ids.length;i++) { System.out.println("Availalbe ids.................."+ids[i]); TimeZone d= TimeZone.getTimeZone(ids[i]); System.out.println("time zone."+d.getDisplayName()); System.out.println("savings."+d.getDSTSavings()); System.out.println("offset."+d.getRawOffset()); ///////////////////////////////////////////////////// if (!ids[i].matches(".*/.*")) { continue; } String region = ids[i].replaceAll(".*/", "").replaceAll("_", " "); int hours = Math.abs(d.getRawOffset()) / 3600000; int minutes = Math.abs(d.getRawOffset() / 60000) % 60; String sign = d.getRawOffset() >= 0 ? "+" : "-"; String timeZonePretty = String.format("(UTC %s %02d:%02d) %s", sign, hours, minutes, region); System.out.println(timeZonePretty); ////////////////////////////////////////////////////////////////// } ListView listitems=(ListView)findViewById(R.id.list); ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ids); listitems.setAdapter(adapter); } 

Documentation for TimeZone. http://developer.android.com/reference/java/util/TimeZone.html

To set the time zone

The following is an example code for setting the time zone according to America

  // First Create Object of Calendar Class Calendar calendar = Calendar.getInstance(); // Now Set the Date using DateFormat Class SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z"); // Finally Set the time zone using SimpleDateFormat Class setTimeZone() Method sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); 
+8
source

Unfortunately, Android settings use this list of time zones from XML included in the Settings app. You can see this in the source code (line 161):

  private List<HashMap> getZones() { List<HashMap> myData = new ArrayList<HashMap>(); long date = Calendar.getInstance().getTimeInMillis(); try { XmlResourceParser xrp = getResources().getXml(R.xml.timezones); ... } 

Other applications, such as Google Calendar, have their own arrays of values. This can be verified by reverse engineering these resources.

So, if you do not want to maintain your own list (given multilingualism ...), I would recommend that you have an abbreviated list provided by java.util.TimeZone and only show the time zones that you want, as @Raghunandan recommended to you in your reply to the answer.

+6
source

All Articles