Here is a quick Java programming tutorial that teaches developers how to obtain a list of every time zone using the java.time package and the java.util library. Enter the following Java code example into your code editor or integrated development environment (IDE) to see how to list time zones:
*/ import java.time.*; import java.util.*; public class TimeZonesInJava { public static void main(String args[]) { TimeZonesInJava timeZonesInJava = new TimeZonesInJava(); timeZonesInJava.proceed(); } private void proceed() { List timeZoneList = new ArrayList<>(ZoneId.getAvailableZoneIds()); System.out.println("Time zones in Java"); int timeZoneIndex = 0; for (String zone : timeZoneList) System.out.println(++timeZoneIndex + ":" + zone); } } /*
When you run this code, you will get the following output. Note: your output may vary based on your system settings:
[root@mypc]# java TimeZonesInJava Time zones in Java 1:Asia/Aden 2:America/Cuiaba 3:Etc/GMT+9 4:Etc/GMT+8 5:Africa/Nairobi ... 598:Europe/Athens 599:US/Pacific 600:Europe/Monaco