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.

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.

Bookmark and Share

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.

Related Posts with Thumbnails

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

tags:

Leave a Reply