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("..."))
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With