Display List Of Timezones In Java
|
|
The Java TimeZone class has a method getAvailableIDs() to get the list of timezones that is supported by Java. The object returns is an array of String objects. You can then get the name of the timezone with the getDisplayName() of the timezone object.
1 2 3 4 5 6 7 8 | String TIMEZONE_ID_PREFIXES = "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*"; String[] ids = TimeZone.getAvailableIDs(); Timezone tz = null; for (int i=0; i<ids.length; i++) { if (ids[i].matches(TIMEZONE_ID_PREFIXES)) { System.out.println(TimeZone.getTimeZone(ids[i]).getDisplayName()); } } |
The list of IDs contains a number of duplicates so with the variable TIMEZONE_ID_PREFIXES, the duplicates will be eliminated. This code was taken from this site. I found it pretty handy when I was working with timezone issues.
Found this post useful? Buy me a cup of coffee or subscribe to my RSS feeds and Google Friend Connect







