To retrieve a list of all available time zones ids we can call the java.time.ZoneId
static method getAvailableZoneIds()
. This method return a Set
of string of all zone ids. The format of the zone id are “{area}/{city}”. You can use these ids of string to create the ZoneId
object using the ZoneId.of()
static method.
package org.kodejava.datetime;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.Set;
public class GetAllTimeZoneIds {
public static void main(String[] args) {
Set<String> zoneIds = ZoneId.getAvailableZoneIds();
for (String id : zoneIds) {
ZoneId zoneId = ZoneId.of(id);
System.out.println("id = " + id);
System.out.println("displayName = " +
zoneId.getDisplayName(TextStyle.FULL, Locale.US));
}
}
}
Here are some zone IDs printed out to the console:
id = Asia/Aden
displayName = Arabian Time
id = America/Cuiaba
displayName = Amazon Time
id = Etc/GMT+9
displayName = GMT-9:00
id = Etc/GMT+8
displayName = GMT-8:00
id = Africa/Nairobi
displayName = Eastern Africa Time
...
...
...
id = Europe/Nicosia
displayName = Eastern European Time
id = Pacific/Guadalcanal
displayName = Solomon Is. Time
id = Europe/Athens
displayName = Eastern European Time
id = US/Pacific
displayName = Pacific Time
id = Europe/Monaco
displayName = Central European Time
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024