+02:00.
A time-zone offset is the amount of time that a time-zone differs from Greenwich/UTC. This is usually a fixed number of hours and minutes.
Different parts of the world have different time-zone offsets.
The rules for how offsets vary by place and time of year are captured in the
ZoneId class.
For example, Paris is one hour ahead of Greenwich/UTC in winter and two hours
ahead in summer. The ZoneId instance for Paris will reference two
ZoneOffset instances - a +01:00 instance for winter,
and a +02:00 instance for summer.
In 2008, time-zone offsets around the world extended from -12:00 to +14:00. To prevent any problems with that range being extended, yet still provide validation, the range of offsets is restricted to -18:00 to 18:00 inclusive.
This class is designed for use with the ISO calendar system. The fields of hours, minutes and seconds make assumptions that are valid for the standard ISO definitions of those fields. This class may be used with other calendar systems providing the definition of the time fields matches those of the ISO calendar system.
Instances of ZoneOffset must be compared using equals.
Implementations may choose to cache certain common offsets, however
applications must not rely on such caching.
This is a value-based
class; programmers should treat instances that are
equal as interchangeable and should not
use instances for synchronization, or unpredictable behavior may
occur. For example, in a future release, synchronization may fail.
The equals method should be used for comparisons.
Implementation Specification
This class is immutable and thread-safe.
| Modifier and Type | Field and Description |
|---|---|
| private final transient String | id
The string form of the time-zone offset. |
| private static final ConcurrentMap | ID_CACHE
Cache of time-zone offset by ID. |
| public static final ZoneOffset | MAX
Constant for the maximum supported offset. |
| private static final int | MAX_SECONDS
The abs maximum seconds. |
| public static final ZoneOffset | MIN
Constant for the minimum supported offset. |
| private static final AtomicReferenceArray | |
| private final transient LazyConstant | rules
The zone rules for an offset will always return this offset. |
| private static final int | SECONDS_PER_QUARTER
Cache of time-zone offset by offset in quarters. |
| private static final long | serialVersionUID
Serialization version.
|
| private final int | |
| public static final ZoneOffset | UTC
The time-zone offset for UTC, with an ID of 'Z'. |
| Access | Constructor and Description |
|---|---|
| private | ZoneOffset(int
the total time-zone offset in seconds, from -64,800 to +64,800 totalSeconds)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public Temporal | Returns: the adjusted object, not nullthe target object to be adjusted, not null temporal)Implements java. Adjusts the specified temporal object to have the same offset as this object. |
| private static String | |
| public int | Returns: the comparator value, that is less than zero if this totalSeconds is less thanother totalSeconds, zero if they are equal,
greater than zero if this totalSeconds is greater than other totalSecondsthe other date to compare to, not null other)Implements java. Compares this offset to another offset in descending order. |
| public boolean | Returns: true if this is equal to the other offsetthe object to check, null returns false obj)Overrides java. Checks if this offset is equal to another offset. |
| public static ZoneOffset | Returns: the zone-offset, not nullthe temporal object to convert, not null temporal)Hides java. Obtains an instance of |
| public int | Returns: the value for the fieldthe field to get, not null field)Overrides default java. Gets the value of the specified field from this offset as an |
| public String | Returns: the zone offset ID, not nullImplements abstract java. Gets the normalized zone offset ID. The ID is minor variation to the standard ISO-8601 formatted string for the offset. |
| public long | Returns: the value for the fieldthe field to get, not null field)Implements java. Gets the value of the specified field from this offset as a |
| pack-priv ZoneOffset | getOffset(long epochSecond)
Implements abstract java. Get the effective offset for an instant at the given epochSecond. |
| public ZoneRules | Returns: the rules, not nullImplements abstract java. Gets the associated time-zone rules. |
| public int | Returns: the total zone offset amount in secondsGets the total zone offset in seconds. |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this offset. |
| public boolean | Returns: true if the field is supported on this offset, false if notthe field to check, null returns false field)Implements java. Checks if the specified field is supported. |
| public ZoneId | normalized()
Overrides java. Normalizes the time-zone ID, returning a |
| public static ZoneOffset | Returns: the zone-offset, not nullthe offset ID, not null offsetId)Hides java. Obtains an instance of
This method parses the string ID of a |
| public static ZoneOffset | Returns: the zone-offset, not nullthe time-zone offset in hours, from -18 to +18 hours)Obtains an instance of |
| public static ZoneOffset | Returns: the zone-offset, not nullthe time-zone offset in hours, from -18 to +18 hours, int the time-zone offset in minutes, from 0 to ±59, sign matches hours minutes)Obtains an instance of |
| public static ZoneOffset | Returns: the zone-offset, not nullthe time-zone offset in hours, from -18 to +18 hours, int the time-zone offset in minutes, from 0 to ±59, sign matches hours and seconds minutes, int the time-zone offset in seconds, from 0 to ±59, sign matches hours and minutes seconds)Obtains an instance of |
| public static ZoneOffset | Returns: the ZoneOffset, not nullthe total time-zone offset in seconds, from -64,800 to +64,800 totalSeconds)Obtains an instance of
The offset must be in the range |
| private static int | Returns: the parsed number, from 0 to 99the offset ID, not null offsetId, int the position to parse, valid pos, boolean should this number be prefixed by a precededByColon precededByColon)Parse a two digit zero-prefixed number. |
| public < the type of the result R> R | Returns: the query result, null may be returned (defined by the query)the query to invoke, not null query)Overrides default java. Queries this offset using the specified query. |
| public ValueRange | Returns: the range of valid values for the field, not nullthe field to query the range for, not null field)Overrides default java. Gets the range of valid values for the specified field. |
| pack-priv static ZoneOffset | |
| private void | readObject(ObjectInputStream
the stream to read s)Hides java. Defend against malicious streams. |
| public String | Returns: a string representation of this offset, not nullOverrides java. Outputs this offset as a |
| private static int | Returns: the total in secondsthe time-zone offset in hours, from -18 to +18 hours, int the time-zone offset in minutes, from 0 to ±59, sign matches hours and seconds minutes, int the time-zone offset in seconds, from 0 to ±59, sign matches hours and minutes seconds)Calculates the total offset in seconds. |
| private static void | validate(int
the time-zone offset in hours, from -18 to +18 hours, int the time-zone offset in minutes, from 0 to ±59 minutes, int the time-zone offset in seconds, from 0 to ±59 seconds)Validates the offset fields. |
| pack-priv void | |
| pack-priv void | |
| private Object | Returns: the instance ofSer, not nullHides java. Writes the object using a dedicated serialized form. |
| id | back to summary |
|---|---|
| private final transient String id The string form of the time-zone offset. | |
| ID_CACHE | back to summary |
|---|---|
| private static final ConcurrentMap<String, ZoneOffset> ID_CACHE Cache of time-zone offset by ID. | |
| MAX | back to summary |
|---|---|
| public static final ZoneOffset MAX Constant for the maximum supported offset. | |
| MAX_SECONDS | back to summary |
|---|---|
| private static final int MAX_SECONDS The abs maximum seconds. | |
| MIN | back to summary |
|---|---|
| public static final ZoneOffset MIN Constant for the minimum supported offset. | |
| QUARTER_CACHE | back to summary |
|---|---|
| private static final AtomicReferenceArray<ZoneOffset> QUARTER_CACHE | |
| rules | back to summary |
|---|---|
| private final transient LazyConstant<ZoneRules> rules The zone rules for an offset will always return this offset. Cache it for efficiency. | |
| SECONDS_PER_QUARTER | back to summary |
|---|---|
| private static final int SECONDS_PER_QUARTER Cache of time-zone offset by offset in quarters. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Serialization version. | |
| totalSeconds | back to summary |
|---|---|
| private final int totalSeconds | |
| UTC | back to summary |
|---|---|
| public static final ZoneOffset UTC The time-zone offset for UTC, with an ID of 'Z'. | |
| ZoneOffset | back to summary |
|---|---|
| private ZoneOffset(int totalSeconds) Constructor.
| |
| adjustInto | back to summary |
|---|---|
| public Temporal adjustInto(Temporal temporal) Implements java. Adjusts the specified temporal object to have the same offset as this object. This returns a temporal object of the same observable type as the input with the offset changed to be the same as this.
The adjustment is equivalent to using
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended temporal = thisOffset.adjustInto(temporal); temporal = temporal.with(thisOffset); This instance is immutable and unaffected by this method call.
| |
| buildId | back to summary |
|---|---|
| private static String buildId(int totalSeconds) | |
| compareTo | back to summary |
|---|---|
| public int compareTo(ZoneOffset other) Implements java. Compares this offset to another offset in descending order.
The offsets are compared in the order that they occur for the same time
of day around the world. Thus, an offset of
The comparison is "consistent with equals", as defined by
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Checks if this offset is equal to another offset. The comparison is based on the amount of the offset in seconds. This is equivalent to a comparison by ID. | |
| from | back to summary |
|---|---|
| public static ZoneOffset from(TemporalAccessor temporal) Hides java. Obtains an instance of
This obtains an offset based on the specified temporal.
A
A
The conversion uses the
This method matches the signature of the functional interface
| |
| get | back to summary |
|---|---|
| public int get(TemporalField field) Overrides default java. Gets the value of the specified field from this offset as an This queries this offset for the value of the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a
If the field is not a
| |
| getId | back to summary |
|---|---|
| public String getId() Implements abstract java. Gets the normalized zone offset ID. The ID is minor variation to the standard ISO-8601 formatted string for the offset. There are three formats:
| |
| getLong | back to summary |
|---|---|
| public long getLong(TemporalField field) Implements java. Gets the value of the specified field from this offset as a This queries this offset for the value of the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a
If the field is not a
| |
| getOffset | back to summary |
|---|---|
| pack-priv ZoneOffset getOffset(long epochSecond) Implements abstract java. Doc from java. Get the effective offset for an instant at the given epochSecond.
| |
| getRules | back to summary |
|---|---|
| public ZoneRules getRules() Implements abstract java. Gets the associated time-zone rules. The rules will always return this offset when queried. The implementation class is immutable, thread-safe and serializable. | |
| getTotalSeconds | back to summary |
|---|---|
| public int getTotalSeconds() Gets the total zone offset in seconds. This is the primary way to access the offset amount. It returns the total of the hours, minutes and seconds fields as a single offset that can be added to a time.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this offset.
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(TemporalField field) Implements java. Checks if the specified field is supported.
This checks if this offset can be queried for the specified field.
If false, then calling the
If the field is a
If the field is not a
| |
| normalized | back to summary |
|---|---|
| public ZoneId normalized() Overrides java. Doc from java. Normalizes the time-zone ID, returning a
The returns a normalized
The normalization checks if the rules of this
| |
| of | back to summary |
|---|---|
| public static ZoneOffset of(String offsetId) Hides java. Obtains an instance of
This method parses the string ID of a
The ID of the returned offset will be normalized to one of the formats
described by The maximum supported range is from +18:00 to -18:00 inclusive.
| |
| ofHours | back to summary |
|---|---|
| public static ZoneOffset ofHours(int hours) Obtains an instance of
| |
| ofHoursMinutes | back to summary |
|---|---|
| public static ZoneOffset ofHoursMinutes(int hours, int minutes) Obtains an instance of The sign of the hours and minutes components must match. Thus, if the hours is negative, the minutes must be negative or zero. If the hours is zero, the minutes may be positive, negative or zero.
| |
| ofHoursMinutesSeconds | back to summary |
|---|---|
| public static ZoneOffset ofHoursMinutesSeconds(int hours, int minutes, int seconds) Obtains an instance of The sign of the hours, minutes and seconds components must match. Thus, if the hours is negative, the minutes and seconds must be negative or zero.
| |
| ofTotalSeconds | back to summary |
|---|---|
| public static ZoneOffset ofTotalSeconds(int totalSeconds) Obtains an instance of
The offset must be in the range
| |
| parseNumber | back to summary |
|---|---|
| private static int parseNumber(CharSequence offsetId, int pos, boolean precededByColon) Parse a two digit zero-prefixed number.
| |
| query | back to summary |
|---|---|
| public <R> R query(TemporalQuery<R> query) Overrides default java. Queries this offset using the specified query.
This queries this offset using the specified query strategy object.
The
The result of this method is obtained by invoking the
| |
| range | back to summary |
|---|---|
| public ValueRange range(TemporalField field) Overrides default java. Gets the range of valid values for the specified field. The range object expresses the minimum and maximum valid values for a field. This offset is used to enhance the accuracy of the returned range. If it is not possible to return the range, because the field is not supported or for some other reason, an exception is thrown.
If the field is a
If the field is not a
| |
| readExternal | back to summary |
|---|---|
| pack-priv static ZoneOffset readExternal(DataInput in) throws IOException | |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws InvalidObjectException Hides java. Defend against malicious streams.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this offset as a | |
| totalSeconds | back to summary |
|---|---|
| private static int totalSeconds(int hours, int minutes, int seconds) Calculates the total offset in seconds.
| |
| validate | back to summary |
|---|---|
| private static void validate(int hours, int minutes, int seconds) Validates the offset fields.
| |
| write | back to summary |
|---|---|
| pack-priv void write(DataOutput out) throws IOException Implements abstract java.
| |
| writeExternal | back to summary |
|---|---|
| pack-priv void writeExternal(DataOutput out) throws IOException | |
| writeReplace | back to summary |
|---|---|
| private Object writeReplace() Hides java. Writes the object using a dedicated serialized form. | |