ZoneOffset
Extends:
Static properties of Class LocalDate
ZoneOffset.MAX_SECONDS = 18 * LocalTime.SECONDS_PER_HOUR;
ZoneOffset.UTC = ZoneOffset.ofTotalSeconds(0);
ZoneOffset.MIN = ZoneOffset.ofTotalSeconds(-ZoneOffset.MAX_SECONDS);
ZoneOffset.MAX = ZoneOffset.ofTotalSeconds(ZoneOffset.MAX_SECONDS);
Static Method Summary
Static Public Methods | ||
public static |
of(offsetId: string): ZoneOffset Obtains an instance of {@code ZoneOffset} using the ID. |
|
public static |
ofHours(hours: number): ZoneOffset |
|
public static |
ofHoursMinutes(hours: number, minutes: number): ZoneOffset |
|
public static |
ofHoursMinutesSeconds(hours: number, minutes: number, seconds: number): ZoneOffset |
|
public static |
ofTotalMinutes(totalMinutes: number): ZoneOffset |
|
public static |
ofTotalSeconds(totalSeconds: number): ZoneOffset |
Constructor Summary
Public Constructor | ||
public |
constructor(totalSeconds: number) |
Method Summary
Public Methods | ||
public |
adjustInto(temporal: Temporal): Temporal Adjusts the specified temporal object to have the same offset as this object. |
|
public |
compareTo(other: ZoneOffset): number Compares this offset to another offset in descending order. |
|
public |
Checks if this offset is equal to another offset. |
|
public |
get(field: TemporalField): number Gets the value of the specified field from this offset as an {@code int}. |
|
public |
getLong(field: TemporalField): number Gets the value of the specified field from this offset as a {@code long}. |
|
public |
|
|
public |
|
|
public |
|
|
public |
query(query: TemporalQuery): * Queries this offset using the specified query. |
|
public |
Gets the associated time-zone rules. |
|
public |
|
|
public |
|
Inherited Summary
From class ZoneId | ||
public |
Checks if this time-zone ID is equal to another time-zone ID. |
|
public |
A hash code for this time-zone ID. |
|
public |
normalized(): ZoneId Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible. |
|
public |
Gets the time-zone rules for this ID allowing calculations to be performed. |
|
public |
Outputs this zone as a {@code String}, using the ID. |
Static Public Methods
public static of(offsetId: string): ZoneOffset source
Obtains an instance of {@code ZoneOffset} using the ID.
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:
- {@code Z} - for UTC
- {@code +h}
- {@code +hh}
- {@code +hh:mm}
- {@code -hh:mm}
- {@code +hhmm}
- {@code -hhmm}
- {@code +hh:mm:ss}
- {@code -hh:mm:ss}
- {@code +hhmmss}
- {@code -hhmmss}
Note that ± means either the plus or minus symbol.
The ID of the returned offset will be normalized to one of the formats described by {@link #getId()}.
The maximum supported range is from +18:00 to -18:00 inclusive.
Params:
Name | Type | Attribute | Description |
offsetId | string | the offset ID, not null |
Throw:
* |
DateTimeException if the offset ID is invalid |
public static ofHours(hours: number): ZoneOffset source
Params:
Name | Type | Attribute | Description |
hours | number |
public static ofHoursMinutes(hours: number, minutes: number): ZoneOffset source
public static ofHoursMinutesSeconds(hours: number, minutes: number, seconds: number): ZoneOffset source
public static ofTotalMinutes(totalMinutes: number): ZoneOffset source
Params:
Name | Type | Attribute | Description |
totalMinutes | number |
public static ofTotalSeconds(totalSeconds: number): ZoneOffset source
Params:
Name | Type | Attribute | Description |
totalSeconds | number |
Public Constructors
Public Methods
public adjustInto(temporal: Temporal): Temporal source
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 {@link Temporal#with(TemporalField, long)} passing ChronoField#OFFSET_SECONDS as the field.
In most cases, it is clearer to reverse the calling pattern by using {@link Temporal#with(TemporalAdjuster)}:
// 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.
Params:
Name | Type | Attribute | Description |
temporal | Temporal | the target object to be adjusted, not null |
Throw:
* |
DateTimeException if unable to make the adjustment |
* |
ArithmeticException if numeric overflow occurs |
public compareTo(other: ZoneOffset): number source
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 {@code +10:00} comes before an offset of {@code +09:00} and so on down to {@code -18:00}.
The comparison is "consistent with equals", as defined by Comparable.
Params:
Name | Type | Attribute | Description |
other | ZoneOffset |
|
the other date to compare to, not null |
Throw:
* |
NullPointerException if {@code other} is null |
public equals(obj: *): boolean source
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.
Override:
ZoneId#equalsParams:
Name | Type | Attribute | Description |
obj | * | the object to check, null returns false |
public get(field: TemporalField): number source
Gets the value of the specified field from this offset as an {@code int}.
This queries this offset for the value for 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 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 a {@code DateTimeException}.
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.
Params:
Name | Type | Attribute | Description |
field | TemporalField | the field to get, not null |
Throw:
* |
DateTimeException if a value for the field cannot be obtained |
* |
ArithmeticException if numeric overflow occurs |
public getLong(field: TemporalField): number source
Gets the value of the specified field from this offset as a {@code long}.
This queries this offset for the value for 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 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 a {@code DateTimeException}.
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.
Params:
Name | Type | Attribute | Description |
field | TemporalField | the field to get, not null |
Throw:
* |
DateTimeException if a value for the field cannot be obtained |
* |
ArithmeticException if numeric overflow occurs |
public query(query: TemporalQuery): * source
Queries this offset using the specified query.
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.
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.
Params:
Name | Type | Attribute | Description |
query | TemporalQuery | the query to invoke, not null |
Return:
* | the query result, null may be returned (defined by the query) |
Throw:
* |
DateTimeException if unable to query (defined by the query) |
* |
ArithmeticException if numeric overflow occurs (defined by the query) |
public rules(): ZoneRules source
Gets the associated time-zone rules.
The rules will always return this offset when queried. The implementation class is immutable, thread-safe and serializable.