java.time.ZoneOffset Class



The java.time.ZoneOffset class represents a time-zone offset from Greenwich/UTC, such as +02:00.

Class declaration

Following is the declaration for java.time.ZoneOffset class −

public final class ZoneOffset
   extends ZoneId
      implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable


Following are the fields for Java.time.ZoneOffset class −

  • static ZoneOffset MAX − Constant for the maximum supported offset.

  • static ZoneOffset MIN − Constant for the minimum supported offset.

  • static ZoneOffset UTC − The time-zone offset for UTC, with an ID of 'Z'.

Class methods

Sr.No. Method & Description
1 Temporal adjustInto(Temporal temporal)

Adjusts the specified temporal object to have the same offset as this object.

2 int compareTo(ZoneOffset other)

Compares this offset to another offset in descending order.

3 boolean equals(Object obj)

Checks if this offset is equal to another offset.

4 static ZoneOffset from(TemporalAccessor temporal)

Obtains an instance of ZoneOffset from a temporal object.

5 int get(TemporalField field)

Gets the value of the specified field from this offset as an int.

6 String getId()

Gets the normalized zone offset ID.

7 long getLong(TemporalField field)

Gets the value of the specified field from this offset as a long.

8 ZoneRules getRules()

Gets the associated time-zone rules.

9 int getTotalSeconds()

Gets the total zone offset in seconds.

10 int hashCode()

A hash code for this offset.

11 boolean isSupported(TemporalField field)

Checks if the specified field is supported.

12 static ZoneOffset of(String offsetId)

Obtains an instance of ZoneOffset using the ID.

13 static ZoneOffset ofHours(int hours)

Obtains an instance of ZoneOffset using an offset in hours.

14 static ZoneOffset ofHoursMinutes(int hours, int minutes)

Obtains an instance of ZoneOffset using an offset in hours and minutes.

15 static ZoneOffset ofHoursMinutesSeconds(int hours, int minutes, int seconds)

Obtains an instance of ZoneOffset using an offset in hours, minutes and seconds.

16 static ZoneOffset ofTotalSeconds(int totalSeconds)

Obtains an instance of ZoneOffset specifying the total offset in seconds.

17 <R> R query(TemporalQuery<R> query)

Queries this offset using the specified query.

18 ValueRange range(TemporalField field)

Gets the range of valid values for the specified field.

19 String toString()

Outputs this offset as a String, using the normalized ID.

Methods inherited

This class inherits methods from the following classes −

  • Java.time.ZoneId
  • Java.lang.Object

E-Books Store