Home Reference Source
public class | source

ZoneOffset

Extends:

ZoneId → ZoneOffset

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 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

Method Summary

Public Methods
public

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

equals(obj: *): boolean

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 int.

public

getLong(field: TemporalField): number

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

public

hashCode(): number

public

id(): string

public

query(query: TemporalQuery): *

Queries this offset using the specified query.

public

Gets the associated time-zone rules.

public

toString(): string

public

totalSeconds(): number

Inherited Summary

From class ZoneId
public static

Obtains an instance of ZoneId from a temporal object.

public static

getAvailableZoneIds(): string[]

Gets the set of available zone IDs.

public static

of(zoneId: string): ZoneId

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

public static

ofOffset(prefix: string, offset: ZoneOffset): ZoneId

Obtains an instance of ZoneId wrapping an offset.

public static

Gets the system default time-zone.

public

equals(other: *): boolean

Checks if this time-zone ID is equal to another time-zone ID.

public

hashCode(): number

A hash code for this time-zone ID.

public

id(): String

Gets the unique time-zone ID.

public

Normalizes the time-zone ID, returning a ZoneOffset where possible.

public

Gets the time-zone rules for this ID allowing calculations to be performed.

public

toJSON(): string

toJSON() use by JSON.stringify delegates to toString()

public

toString(): string

Outputs this zone as a string, using the ID.

Static Public Methods

public static of(offsetId: string): ZoneOffset source

Obtains an instance of ZoneOffset using the ID.

This method parses the string ID of a ZoneOffset to return an instance. The parsing accepts all the formats generated by getId, plus some additional formats:

  • Z - for UTC
  • +h
  • +hh
  • +hh:mm
  • -hh:mm
  • +hhmm
  • -hhmm
  • +hh:mm:ss
  • -hh:mm:ss
  • +hhmmss
  • -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 getId.

The maximum supported range is from +18:00 to -18:00 inclusive.

Override:

ZoneId#of

Params:

NameTypeAttributeDescription
offsetId string

the offset ID, not null

Return:

ZoneOffset

the zone-offset, not null

Throw:

*

DateTimeException if the offset ID is invalid

public static ofHours(hours: number): ZoneOffset source

Params:

NameTypeAttributeDescription
hours number

Return:

ZoneOffset

public static ofHoursMinutes(hours: number, minutes: number): ZoneOffset source

Params:

NameTypeAttributeDescription
hours number
minutes number

Return:

ZoneOffset

public static ofHoursMinutesSeconds(hours: number, minutes: number, seconds: number): ZoneOffset source

Params:

NameTypeAttributeDescription
hours number
minutes number
seconds number

Return:

ZoneOffset

public static ofTotalMinutes(totalMinutes: number): ZoneOffset source

Params:

NameTypeAttributeDescription
totalMinutes number

Return:

ZoneOffset

public static ofTotalSeconds(totalSeconds: number): ZoneOffset source

Params:

NameTypeAttributeDescription
totalSeconds number

Return:

ZoneOffset

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 Temporal#with passing ChronoField#OFFSET_SECONDS as the field.

In most cases, it is clearer to reverse the calling pattern by using Temporal#with:

  // 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:

NameTypeAttributeDescription
temporal Temporal

the target object to be adjusted, not null

Return:

Temporal

the adjusted object, 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 +10:00 comes before an offset of +09:00 and so on down to -18:00.

The comparison is "consistent with equals", as defined by Comparable.

Params:

NameTypeAttributeDescription
other ZoneOffset
  • nullable: false

the other date to compare to, not null

Return:

number

the comparator value, negative if less, positive if greater

Throw:

*

NullPointerException if 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#equals

Params:

NameTypeAttributeDescription
obj *

the object to check, null returns false

Return:

boolean

true if this is equal to the other offset

public get(field: TemporalField): number source

Gets the value of the specified field from this offset as an 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 OFFSET_SECONDS field returns the value of the offset. All other ChronoField instances will throw a DateTimeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

Params:

NameTypeAttributeDescription
field TemporalField

the field to get, not null

Return:

number

the value for the field

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 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 OFFSET_SECONDS field returns the value of the offset. All other ChronoField instances will throw a DateTimeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

Params:

NameTypeAttributeDescription
field TemporalField

the field to get, not null

Return:

number

the value for the field

Throw:

*

DateTimeException if a value for the field cannot be obtained

*

ArithmeticException if numeric overflow occurs

public hashCode(): number source

A hash code for this time-zone ID.

Override:

ZoneId#hashCode

Return:

number

public id(): string source

Gets the unique time-zone ID.

This ID uniquely defines this object. The format of an offset based ID is defined by ZoneOffset#getId.

Override:

ZoneId#id

Return:

string

public query(query: TemporalQuery): * source

Queries this offset using the specified query.

This queries this offset using the specified query strategy object. The 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 TemporalQuery#queryFrom method on the specified query passing this as the argument.

Params:

NameTypeAttributeDescription
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.

Override:

ZoneId#rules

Return:

ZoneRules

the rules, not null

public toString(): string source

Outputs this zone as a string, using the ID.

Override:

ZoneId#toString

Return:

string

public totalSeconds(): number source

Return:

number