Javatpoint Logo
Javatpoint Logo

Java ZoneId Class

Java ZoneId class specifies a time zone identifier and provides a rule for converting between an Instant and a LocalDateTime. It inherits Object class and implements the Serializable interface.

There are two sorts of ID:

  1. Fixed offsets are fully resolved offsets from UTC/Greenwich that apply to all local date-times.
  2. Geographical regions are areas where a set of rules for determining the offset from UTC/Greenwich apply.

Java ZoneId Class Declaration

Let's see the declaration of java.time.ZoneId class.

To allow for the use of short time-zone names, a zone map overrides are employed. In java.util.TimeZone, the usage of short zone IDs is discouraged. The IDs can still be utilised using the of(String, Map) factory function thanks to the map. The map contains a mapping of the IDs that is compatible with TZDB 2005r and later, where 'EST,' 'MST,' and 'HST' correspond to IDs that do not include daylight savings time.

Methods of Java ZoneId Class

Method Description
String getDisplayName(TextStyle style, Locale locale) It is used to get the textual representation of the zone, such as 'India Time' or '+05:30'.
abstract String getId() It is used to get the unique time-zone ID.
static ZoneId of(String zoneId) It is used to obtain an instance of ZoneId from an ID ensuring that the ID is valid and available for use.
static ZoneId systemDefault() It is used to get the system default time-zone.
boolean equals(Object obj) It is used to check if this time-zone ID is equal to another time-zone ID.
static ZoneId from(TemporalAccessor temporal) It obtains an instance of ZoneId from a temporal object.
static Set getAvailableZoneIds() It gets the set of available zone IDs.
abstract ZoneRules getRules() It gets the time-zone rules for this ID allowing calculations to be performed.
int hashCode() It returns a hash code for this time-zone ID.
ZoneId normalized() It normalizes the time-zone ID, returning a ZoneOffset where possible.
static ZoneId of(String zoneId, Map aliasMap) It obtains an instance of ZoneId using its ID using a map of aliases to supplement the standard zone IDs.
static ZoneId ofOffset(String prefix, ZoneOffset offset) It obtains an instance of ZoneId wrapping an offset.
String toString() It outputs this zone as a String, using the ID.

Java ZoneId Class Example

Test it Now



Java ZoneId Class Example: systemDefault()

Test it Now



Java ZoneId Class Example: getId()

Test it Now



Java ZoneId Class Example: getDisplayName()

Test it Now


India Time

Next TopicJava ZoneOffset

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA