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

ZoneIdExample1.java

Test it Now

Output:

14:28:58.230
17:58:58.230
true

Java ZoneId Class Example: systemDefault()

ZoneIdExample2.java

Test it Now

Output:

Asia/Kolkata

Java ZoneId Class Example: getId()

ZoneIdExample3.java

Test it Now

Output:

Asia/Kolkata

Java ZoneId Class Example: getDisplayName()

ZoneIdExample4.java

Test it Now

Output:

India Time

Next TopicJava ZoneOffset





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA