One can obtain this list either through using the Java ZoneId or TimeZone Classes.
The ZoneId Class is defined here:
https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html
The following code will print all the time zones using the ZoneId Class
package com.javadb;
import java.time.ZoneId;
import java.util.TreeSet;
/**
* Displays available time zones (zoneIds)
*
* @author www.javadb.com
*/
public class DisplayTimeZones {
public static void main(String[] args) {
TreeSet<String> sortedZones = new TreeSet<>(ZoneId.getAvailableZoneIds());
System.out.println("Number of zones: " + sortedZones.size());
System.out.println("");
for (String zone : sortedZones) {
System.out.println(zone);
}
//Or if you want to use functional operations
/*
sortedZones.stream().forEach((zone) -> {
System.out.println(zone);
});
*/
}
}
Output:
Number of zones: 585
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
...
Using the Java TimeZone class java.util.TimeZone
the list can be obtained by calling:
TimeZone.getAvailableIDs()
In addition, if one uses Joda-Time, the Class DateTimeZone getAvailableIDs()
will work as well.