Last Updated : 23 Jul, 2025
A ZoneId is used to identify the rules that used to convert between a LocalDateTime and an Instant of time. The actual rules, describing when and the way the offset changes, are defined by ZoneRules. This class is just an ID wont to obtain the underlying rules. The given approach has opted because the government defines the rules and alters frequently, whereas the ID is stable.
There are two distinct types of ID:
Declaration of java.time.ZoneId class
public abstract class ZoneId extends Object implements Serializable
A zone map overrides to enable the short time-zone names to be used. The use of short zone IDs has been deprecated in java.util.TimeZone. This map allows the IDs to still be used via the of(String, Map) factory method. This map contains a mapping of the IDs that's in line with TZDB 2005r and later, where 'EST', 'MST' and 'HST' map to IDs that don't include daylight savings.
This maps as follows:
EST
05:00HST
10:00MST
07:00ACT
Australia/DarwinAET
Australia/SydneyAGT
America/Argentina/Buenos_AiresART
Africa/CairoAST
America/AnchorageBET
America/Sao_PauloBST
Asia/DhakaCAT
Africa/HarareCNT
America/St_JohnsCST
America/ChicagoCTT
Asia/ShanghaiEAT
Africa/Addis_AbabaECT
Europe/ParisIET
America/Indiana/IndianapolisIST
Asia/KolkataJST
Asia/TokyoMIT
Pacific/ApiaNET
Asia/YerevanNST
Pacific/AucklandPLT
Asia/KarachiPNT
America/PhoenixPRT
America/Puerto_RicoPST
America/Los_AngelesSST
Pacific/Guadalcanal VST Asia/Ho_Chi_MinhNote: The map is unmodifiable.
Methods of ZoneId class:
Methods Description equals(Object obj) This method checks if this time-zone ID is equal to another time-zone ID. from(TemporalAccessor temporal) This method obtains an instance of ZoneId from a temporal object. getAvailableZoneIds() This method gets the set of available zone IDs. getDisplayName(TextStyle style, Locale locale) This method gets the textual representation of the zone, such as 'British Time' or '+02:00'. getId() This method gets the unique time-zone ID. getRules() This method gets the time-zone rules for this ID allowing calculations to be performed. hashCode() A hash code for this time-zone ID. normalized() This method normalizes the time-zone ID, returning a ZoneOffset where possible. of(String zoneId) This method obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use. of(String zoneId, Map<String,String> aliasMap) This method obtains an instance of ZoneId using its ID using a map of aliases to supplement the standard zone IDs. ofOffset(String prefix, ZoneOffset offset) This method obtains an instance of ZoneId wrapping an offset. systemDefault() This method gets the system default time-zone. toString() This method outputs this zone as a String, using the ID.Below is an example of the implementation of some methods:
Java
// java.time.ZoneId Class in Java with example
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// Setting Zone1
ZoneId zoneid1 = ZoneId.of("Asia/Kolkata");
// Setting Zone2
ZoneId zoneid2 = ZoneId.of("Europe/London");
LocalTime time1 = LocalTime.now(zoneid1);
LocalTime time2 = LocalTime.now(zoneid2);
System.out.println(time1);
System.out.println(time2);
// Checking if the time of zone1
// comes before time of second zone
System.out.println(time1.isBefore(time2));
}
}
22:34:11.044312 17:04:11.044385 false
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4