Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the official list of zone names for java.time?

Tags:

java

java-time

Is there an official list of zone names that are used for the following:

zoneId = ZoneId.of("America/New_York")

Or is it possible for java.time.ZoneId to generate the list itself that I can use?

I'm using this to convert an Instant to a string representation of time like:

ZoneDateTime.ofInstant(instant, zoneId).format(DateTimeFormatter.ofPattern("..."))
like image 377
Blankman Avatar asked Feb 28 '17 15:02

Blankman


2 Answers

Just use the getAvailableZoneIds method.

Gets the set of available zone IDs.

This set includes the string form of all available region-based IDs. Offset-based zone IDs are not included in the returned set. The ID can be passed to of(String) to create a ZoneId.

Set<String> zoneIds= ZoneId.getAvailableZoneIds();

for (String zone : zoneIds) {
    System.out.println(zone);
}
like image 118
Arnaud Avatar answered Nov 17 '22 18:11

Arnaud


As other answers have said, the way to get this list in your code is to use ZoneId.getAvailableZoneIds().

However, if you just to browse want an "official" list, the data is available from IANA, but this is in a format intended for machines. The easiest way to peruse the data is on Wikipedia. (With usual disclaimer that Wikipedia is Wikipedia...)

You should also be aware that recent changes to IANA/Wikipedia data might not be present in your target JRE if it has not been updated recently.

like image 14
Kip Avatar answered Nov 17 '22 18:11

Kip