ZoneId class represents a combination of a zone offset and the rules for changing the zone offset for observed Daylight Saving Time.
Not all time zones observe Daylight Saving Time.
You can think of it as
ZoneId = ZoneOffset + ZoneRules
ZoneOffset represents a fixed zone offset from UtC time zone whereas a ZoneId represents a variable zone offset.
ZoneOffset class inherits from the ZoneId class.
A time zone has a unique textual ID, which can be specified in three formats:
The first two forms of Zone IDs create a ZoneId with a fixed zone offset. You can create a ZoneId using the of() factory method.
ZoneId usChicago = ZoneId.of("America/Chicago"); ZoneId bdDhaka = ZoneId.of("Asia/Dhaka"); ZoneId fixedZoneId = ZoneId.of("+06:00");
ZoneId class provides access to all known time zone IDs.
Its getAvailableZoneIds() static method returns a Set<String> containing all available zone Ids.
The following code shows how to print all zone IDs.
import java.time.ZoneId; import java.util.Set; public class Main { public static void main(String[] args) { Set<String> zoneIds = ZoneId.getAvailableZoneIds(); for (String zoneId: zoneIds) { System.out.println(zoneId); }// w w w .j a va2 s . c o m } }