java.time.ZoneId Class in Java
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:
- Fixed offsets is a fully resolved offset from UTC/Greenwich, that uses the same offset for all local date-times
- Geographical regions are a neighborhood where a selected set of rules for locating the offset from UTC/Greenwich apply
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 HST MST ACT AET AGT ART AST BET BST CAT CNT CST CTT EAT ECT IET IST JST MIT NET NST PLT PNT PRT PST SST
05:00 10:00 07:00 Australia/Darwin Australia/Sydney America/Argentina/Buenos_Aires Africa/Cairo America/Anchorage America/Sao_Paulo Asia/Dhaka Africa/Harare America/St_Johns America/Chicago Asia/Shanghai Africa/Addis_Ababa Europe/Paris America/Indiana/Indianapolis Asia/Kolkata Asia/Tokyo Pacific/Apia Asia/Yerevan Pacific/Auckland Asia/Karachi America/Phoenix America/Puerto_Rico America/Los_Angeles Pacific/Guadalcanal VST Asia/Ho_Chi_Minh
Note: 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:
22:34:11.044312 17:04:11.044385 false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.