ZoneOffset

A time-zone offset from Greenwich/UTC, such as {@code +02:00}. !(p) 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. !(p) 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 {@link ZoneId} class. !(p) For example, Paris is one hour ahead of Greenwich/UTC _in winter and two hours ahead _in summer. The {@code ZoneId} instance for Paris will reference two {@code ZoneOffset} instances - a {@code +01:00} instance for winter, and a {@code +02:00} instance for summer. !(p) 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. !(p) 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. !(p) Instances of {@code ZoneOffset} must be compared using {@link #equals}. Implementations may choose to cache certain common offsets, however applications must not rely on such caching.

!(p) This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a> class; use of identity-sensitive operations (including reference equality ({@code ==}), identity hash code, or synchronization) on instances of {@code ZoneOffset} may have unpredictable results and should be avoided. The {@code equals} method should be used for comparisons.

@implSpec This class is immutable and thread-safe.

@since 1.8

Members

Functions

adjustInto
Temporal adjustInto(Temporal temporal)

Adjusts the specified temporal object to have the same offset as this object. !(p) This returns a temporal object of the same observable type as the input with the offset changed to be the same as this. !(p) The adjustment is equivalent to using {@link Temporal#_with(TemporalField, long)} passing {@link ChronoField#OFFSET_SECONDS} as the field. !(p) In most cases, it is clearer to reverse the calling pattern by using {@link Temporal#_with(TemporalAdjuster)}: !(pre) // these two lines are equivalent, but the second approach is recommended temporal = thisOffset.adjustInto(temporal); temporal = temporal._with(thisOffset); </pre> !(p) This instance is immutable and unaffected by this method call.

compareTo
int compareTo(ZoneOffset other)

Compares this offset to another offset _in descending order. !(p) The offsets are compared _in the order that they occur for the same time of day around the world. Thus, an offset of {@code +10:00} comes before an offset of {@code +09:00} and so on down to {@code -18:00}. !(p) The comparison is "consistent with equals", as defined by {@link Comparable}.

get
int get(TemporalField field)

Gets the value of the specified field from this offset as an {@code int}. !(p) 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. !(p) If the field is a {@link ChronoField} then the query is implemented here. The {@code OFFSET_SECONDS} field returns the value of the offset. All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} passing {@code this} as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

getId
string getId()

Gets the normalized zone offset ID. !(p) The ID is minor variation to the standard ISO-8601 formatted string for the offset. There are three formats: !(ul) !(li){@code Z} - for UTC (ISO-8601) !(li){@code +hh:mm} or {@code -hh:mm} - if the seconds are zero (ISO-8601) !(li){@code +hh:mm:ss} or {@code -hh:mm:ss} - if the seconds are non-zero (not ISO-8601) </ul>

getLong
long getLong(TemporalField field)

Gets the value of the specified field from this offset as a {@code long}. !(p) 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. !(p) If the field is a {@link ChronoField} then the query is implemented here. The {@code OFFSET_SECONDS} field returns the value of the offset. All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} passing {@code this} as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

getRules
ZoneRules getRules()

Gets the associated time-zone rules. !(p) The rules will always return this offset when queried. The implementation class is immutable, thread-safe and serializable.

getTotalSeconds
int getTotalSeconds()

Gets the total zone offset _in seconds. !(p) 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.

isSupported
bool isSupported(TemporalField field)

Checks if the specified field is supported. !(p) This checks if this offset can be queried for the specified field. If false, then calling the {@link #range(TemporalField) range} and {@link #get(TemporalField) get} methods will throw an exception. !(p) If the field is a {@link ChronoField} then the query is implemented here. The {@code OFFSET_SECONDS} field returns true. All other {@code ChronoField} instances will return false. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} passing {@code this} as the argument. Whether the field is supported is determined by the field.

opCmp
int opCmp(ZoneOffset other)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object obj)

Checks if this offset is equal to another offset. !(p) The comparison is based on the amount of the offset _in seconds. This is equivalent to a comparison by ID.

query
R query(TemporalQuery!(R) query)

Queries this offset using the specified query. !(p) This queries this offset using the specified query strategy object. The {@code TemporalQuery} object defines the logic to be used to obtain the result. Read the documentation of the query to understand what the result of this method will be. !(p) The result of this method is obtained by invoking the {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the specified query passing {@code this} as the argument.

range
ValueRange range(TemporalField field)

Gets the range of valid values for the specified field. !(p) 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. !(p) If the field is a {@link ChronoField} then the query is implemented here. The {@link #isSupported(TemporalField) supported fields} will return appropriate range instances. All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} passing {@code this} as the argument. Whether the range can be obtained is determined by the field.

super_query
R super_query(TemporalQuery!(R) query)
Undocumented in source. Be warned that the author may not have intended to support it.
super_range
ValueRange super_range(TemporalField field)
Undocumented in source. Be warned that the author may not have intended to support it.
toHash
size_t toHash()

A hash code for this offset.

toString
string toString()

Outputs this offset as a {@code string}, using the normalized ID.

Static functions

ID_CACHE
HashMap!(string, ZoneOffset) ID_CACHE()

Cache of time-zone offset by ID.

MAX
ZoneOffset MAX()

Constant for the maximum supported offset.

MIN
ZoneOffset MIN()

Constant for the minimum supported offset.

UTC
ZoneOffset UTC()

The time-zone offset for UTC, with an ID of 'Z'.

from
ZoneOffset from(TemporalAccessor temporal)

Obtains an instance of {@code ZoneOffset} from a temporal object. !(p) This obtains an offset based on the specified temporal. A {@code TemporalAccessor} represents an arbitrary set of date and time information, which this factory converts to an instance of {@code ZoneOffset}. !(p) A {@code TemporalAccessor} represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of {@code ZoneOffset}. !(p) The conversion uses the {@link TemporalQueries#offset()} query, which relies on extracting the {@link ChronoField#OFFSET_SECONDS OFFSET_SECONDS} field. !(p) This method matches the signature of the functional interface {@link TemporalQuery} allowing it to be used as a query via method reference, {@code ZoneOffset::from}.

of
ZoneOffset of(string offsetId)

Obtains an instance of {@code ZoneOffset} using the ID. !(p) This method parses the string ID of a {@code ZoneOffset} to return an instance. The parsing accepts all the formats generated by {@link #getId()}, plus some additional formats: !(ul) !(li){@code Z} - for UTC !(li){@code +h} !(li){@code +hh} !(li){@code +hh:mm} !(li){@code -hh:mm} !(li){@code +hhmm} !(li){@code -hhmm} !(li){@code +hh:mm:ss} !(li){@code -hh:mm:ss} !(li){@code +hhmmss} !(li){@code -hhmmss} </ul> Note that &plusmn; means either the plus or minus symbol. !(p) The ID of the returned offset will be normalized to one of the formats described by {@link #getId()}. !(p) The maximum supported range is from +18:00 to -18:00 inclusive.

ofHours
ZoneOffset ofHours(int hours)

Obtains an instance of {@code ZoneOffset} using an offset _in hours.

ofHoursMinutes
ZoneOffset ofHoursMinutes(int hours, int minutes)

Obtains an instance of {@code ZoneOffset} using an offset _in hours and minutes. !(p) 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
ZoneOffset ofHoursMinutesSeconds(int hours, int minutes, int seconds)

Obtains an instance of {@code ZoneOffset} using an offset _in hours, minutes and seconds. !(p) 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
ZoneOffset ofTotalSeconds(int _totalSeconds)

Obtains an instance of {@code ZoneOffset} specifying the total offset _in seconds !(p) The offset must be _in the range {@code -18:00} to {@code +18:00}, which corresponds to -64800 to +64800.

Variables

MAX_SECONDS
enum int MAX_SECONDS;

The abs maximum seconds.

Inherited Members

From ZoneId

SHORT_IDS
Map!(string, string) SHORT_IDS()

A map of zone overrides to enable the short time-zone names to be used. !(p) Use of short zone IDs has been deprecated _in {@code java.util.TimeZone}. This map allows the IDs to continue to be used via the {@link #of(string, Map)} factory method. !(p) This map contains a mapping of the IDs that is _in line with TZDB 2005r and later, where 'EST', 'MST' and 'HST' map to IDs which do not include daylight savings. !(p) This maps as follows: !(ul) !(li)EST - -05:00</li> !(li)HST - -10:00</li> !(li)MST - -07:00</li> !(li)ACT - Australia/Darwin</li> !(li)AET - Australia/Sydney</li> !(li)AGT - America/Argentina/Buenos_Aires</li> !(li)ART - Africa/Cairo</li> !(li)AST - America/Anchorage</li> !(li)BET - America/Sao_Paulo</li> !(li)BST - Asia/Dhaka</li> !(li)CAT - Africa/Harare</li> !(li)CNT - America/St_Johns</li> !(li)CST - America/Chicago</li> !(li)CTT - Asia/Shanghai</li> !(li)EAT - Africa/Addis_Ababa</li> !(li)ECT - Europe/Paris</li> !(li)IET - America/Indiana/Indianapolis</li> !(li)IST - Asia/Kolkata</li> !(li)JST - Asia/Tokyo</li> !(li)MIT - Pacific/Apia</li> !(li)NET - Asia/Yerevan</li> !(li)NST - Pacific/Auckland</li> !(li)PLT - Asia/Karachi</li> !(li)PNT - America/Phoenix</li> !(li)PRT - America/Puerto_Rico</li> !(li)PST - America/Los_Angeles</li> !(li)SST - Pacific/Guadalcanal</li> !(li)VST - Asia/Ho_Chi_Minh</li> </ul> The map is unmodifiable.

systemDefault
deprecated ZoneId systemDefault()
Undocumented in source. Be warned that the author may not have intended to support it.
of
deprecated ZoneId of(string zoneId, Map!(string, string) aliasMap)

Gets the set of available zone IDs. !(p) This set includes the string form of all available region-based IDs. Offset-based zone IDs are not included _in the returned set. The ID can be passed to {@link #of(string)} to create a {@code ZoneId}. !(p) The set of zone IDs can increase over time, although _in a typical application the set of IDs is fixed. Each call to this method is thread-safe.

of
deprecated ZoneId of(string zoneId)
Undocumented in source. Be warned that the author may not have intended to support it.
ofOffset
deprecated ZoneId ofOffset(string prefix, ZoneOffset offset)

Obtains an instance of {@code ZoneId} wrapping an offset. !(p) If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId} with the prefix and the non-zero offset is returned. If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.

of
deprecated ZoneId of(string zoneId, bool checkAvailable)

Parses the ID, taking a flag to indicate whether {@code ZoneRulesException} should be thrown or not, used _in deserialization.

from
ZoneId from(TemporalAccessor temporal)

Obtains an instance of {@code ZoneId} from a temporal object. !(p) This obtains a zone based on the specified temporal. A {@code TemporalAccessor} represents an arbitrary set of date and time information, which this factory converts to an instance of {@code ZoneId}. !(p) A {@code TemporalAccessor} represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of {@code ZoneId}. !(p) The conversion will try to obtain the zone _in a way that favours region-based zones over offset-based zones using {@link TemporalQueries#zone()}. !(p) This method matches the signature of the functional interface {@link TemporalQuery} allowing it to be used as a query via method reference, {@code ZoneId::from}.

getId
string getId()

Gets the unique time-zone ID. !(p) This ID uniquely defines this object. The format of an offset based ID is defined by {@link ZoneOffset#getId()}.

getRules
ZoneRules getRules()

Gets the time-zone rules for this ID allowing calculations to be performed. !(p) The rules provide the functionality associated with a time-zone, such as finding the offset for a given instant or local date-time. !(p) A time-zone can be invalid if it is deserialized _in a Java Runtime which does not have the same rules loaded as the Java Runtime that stored it. In this case, calling this method will throw a {@code ZoneRulesException}. !(p) The rules are supplied by {@link ZoneRulesProvider}. An advanced provider may support dynamic updates to the rules without restarting the Java Runtime. If so, then the result of this method may change over time. Each individual call will be still remain thread-safe. !(p) {@link ZoneOffset} will always return a set of rules where the offset never changes.

normalized
ZoneId normalized()

Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible. !(p) The returns a normalized {@code ZoneId} that can be used _in place of this ID. The result will have {@code ZoneRules} equivalent to those returned by this object, however the ID returned by {@code getId()} may be different. !(p) The normalization checks if the rules of this {@code ZoneId} have a fixed offset. If they do, then the {@code ZoneOffset} equal to that offset is returned. Otherwise {@code this} is returned.

opEquals
bool opEquals(Object obj)

Checks if this time-zone ID is equal to another time-zone ID. !(p) The comparison is based on the ID.

toHash
size_t toHash()

A hash code for this time-zone ID.

toString
string toString()

Outputs this zone as a {@code string}, using the ID.

From TemporalAccessor

isSupported
bool isSupported(TemporalField field)

Checks if the specified field is supported. !(p) This checks if the date-time can be queried for the specified field. If false, then calling the {@link #range(TemporalField) range} and {@link #get(TemporalField) get} methods will throw an exception.

range
ValueRange range(TemporalField field)

Gets the range of valid values for the specified field. !(p) All fields can be expressed as a {@code long} integer. This method returns an object that describes the valid range for that value. The value of this temporal object is used to enhance the accuracy of the returned range. If the date-time cannot return the range, because the field is unsupported or for some other reason, an exception will be thrown. !(p) Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.

get
int get(TemporalField field)

Gets the value of the specified field as an {@code int}. !(p) This queries the date-time for the value of the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.

getLong
long getLong(TemporalField field)

Gets the value of the specified field as a {@code long}. !(p) This queries the date-time for the value of the specified field. The returned value may be outside the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.

query
R query(TemporalQuery!(R) query)

Queries this date-time. !(p) This queries this date-time using the specified query strategy object. !(p) Queries are a key tool for extracting information from date-times. They exists to externalize the process of querying, permitting different approaches, as per the strategy design pattern. Examples might be a query that checks if the date is the day before February 29th _in a leap year, or calculates the number of days to your next birthday. !(p) The most common query implementations are method references, such as {@code LocalDate::from} and {@code ZoneId::from}. Additional implementations are provided as static methods on {@link TemporalQuery}.

toString
string toString()
Undocumented in source.

From TemporalAdjuster

adjustInto
Temporal adjustInto(Temporal temporal)

Adjusts the specified temporal object. !(p) This adjusts the specified temporal object using the logic encapsulated _in the implementing class. Examples might be an adjuster that sets the date avoiding weekends, or one that sets the date to the last day of the month. !(p) There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use {@link Temporal#_with(TemporalAdjuster)}: !(pre) // these two lines are equivalent, but the second approach is recommended temporal = thisAdjuster.adjustInto(temporal); temporal = temporal._with(thisAdjuster); </pre> It is recommended to use the second approach, {@code _with(TemporalAdjuster)}, as it is a lot clearer to read _in code.

Meta