ZoneId getAvailableZoneIds() example

Description

ZoneId getAvailableZoneIds() gets the set of available zone IDs.

Syntax

getAvailableZoneIds has the following syntax.


public static Set<String> getAvailableZoneIds()

Example

The following example shows how to use getAvailableZoneIds.


import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/*from   ww  w  .  j a  v a2 s.co  m*/
public class Main {
  public static void main(String[] args) {
    Set<String> allZones = ZoneId.getAvailableZoneIds();
    List<String> zoneList = new ArrayList<String>(allZones);
    Collections.sort(zoneList);

    LocalDateTime dt = LocalDateTime.now();
    for (String s : zoneList) {
      ZoneId zone = ZoneId.of(s);
      ZonedDateTime zdt = dt.atZone(zone);
      ZoneOffset offset = zdt.getOffset();
      String out = String.format("%35s %10s%n", zone, offset);
      System.out.println(out);
    }
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset