Home Reference Source
public class | source

OffsetTime

Extends:

TemporalAccessorTemporal → OffsetTime

A time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00.

Static Method Summary

Static Public Methods
public static
public static

now(clockOrZone: Clock | ZoneId): OffsetTime

public static
public static

ofInstant(instant: Instant, zone: ZoneId): OffsetTime

public static

ofNumbers(hour: int, minute: int, second: int, nanoOfSecond: int, offset: ZoneOffset): OffsetTime

public static
public static

parse(text: string, formatter: DateTimeFormatter): OffsetTime

Method Summary

Public Methods
public
public
public

compareTo(other: OffsetTime): int

public

equals(other: *): boolean

public

format(formatter: DateTimeFormatter): string

public

get(field: TemporalField): number

public

getLong(field: TemporalField): number

public

hashCode(): number

public

hour(): int

public

isAfter(other: OffsetTime): boolean

public

isBefore(other: OffsetTime): boolean

public

isEqual(other: OffsetTime): boolean

public

isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean

public

minusHours(hours: number): OffsetTime

public

minusMinutes(minutes: number): OffsetTime

public

minusNanos(nanos: number): OffsetTime

public

minusSeconds(seconds: number): OffsetTime

public

minute(): int

public

nano(): int

public
public

plusHours(hours: int): OffsetTime

public

plusMinutes(minutes: int): OffsetTime

public

plusNanos(nanos: int): OffsetTime

public

plusSeconds(seconds: int): OffsetTime

public

query(query: TemporalQuery): *

public
public

second(): int

public

toJSON(): string

public
public

toString(): string

public
public

until(endExclusive: Temporal, unit: TemporalUnit): number

public

withHour(hour: int): OffsetTime

public

withMinute(minute: int): OffsetTime

public

withNano(nano: int): OffsetTime

public
public
public

withSecond(second: int): OffsetTime

Inherited Summary

From class TemporalAccessor
public

get(field: TemporalField): number

Gets the value of the specified field as an int.

public

getLong(field: *)

public

isSupported(field: *)

public

query(query: TemporalQuery): *

Queries this date-time.

public

Gets the range of valid values for the specified field.

From class Temporal
public

isSupported(fieldOrUnit: TemporalUnit): boolean

Checks if the specified unit is supported.

public

minus(amount: TemporalAmount | number, unit: TemporalUnit): Temporal

function overloading for Temporal.plus

public

plus(amount: TemporalAmount | number, unit: TemporalUnit): Temporal

function overloading for Temporal.plus

public

until(endTemporal: Temporal, unit: TemporalUnit): number

Calculates the period between this temporal and another temporal in terms of the specified unit.

public

with(adjusterOrField: TemporalAdjuster | TemporalField, newValue: number): Temporal

function overloading for Temporal.with

Static Public Methods

public static from(temporal: TemporalAccessor): OffsetTime source

Params:

NameTypeAttributeDescription
temporal TemporalAccessor
  • nullable: false

Return:

OffsetTime

public static now(clockOrZone: Clock | ZoneId): OffsetTime source

Params:

NameTypeAttributeDescription
clockOrZone Clock | ZoneId

Return:

OffsetTime

public static of(): OffsetTime source

Return:

OffsetTime

public static ofInstant(instant: Instant, zone: ZoneId): OffsetTime source

Params:

NameTypeAttributeDescription
instant Instant
  • nullable: false
zone ZoneId
  • nullable: false

Return:

OffsetTime (nullable: false)

public static ofNumbers(hour: int, minute: int, second: int, nanoOfSecond: int, offset: ZoneOffset): OffsetTime source

Params:

NameTypeAttributeDescription
hour int
minute int
second int
nanoOfSecond int
offset ZoneOffset

Return:

OffsetTime

public static ofTimeAndOffset(time: LocalTime, offset: ZoneOffset): OffsetTime source

Params:

NameTypeAttributeDescription
time LocalTime
offset ZoneOffset

Return:

OffsetTime

public static parse(text: string, formatter: DateTimeFormatter): OffsetTime source

Params:

NameTypeAttributeDescription
text string
formatter DateTimeFormatter

Return:

OffsetTime

Public Methods

public adjustInto(temporal: TemporalAdjuster): Temporal source

Params:

NameTypeAttributeDescription
temporal TemporalAdjuster

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 atDate(date: LocalDate): OffsetDateTime source

Params:

NameTypeAttributeDescription
date LocalDate

the date to combine with, not null

Return:

OffsetDateTime

the offset date-time formed from this time and the specified date, not null

public compareTo(other: OffsetTime): int source

Params:

NameTypeAttributeDescription
other OffsetTime

the other time to compare to, not null

Return:

int

the comparator value, negative if less, positive if greater

Throw:

NullPointerException

if other is null

public equals(other: *): boolean source

Params:

NameTypeAttributeDescription
other *

the object to check, null returns false

Return:

boolean

true if this is equal to the other time

public format(formatter: DateTimeFormatter): string source

Params:

NameTypeAttributeDescription
formatter DateTimeFormatter

the formatter to use, not null

Return:

string

the formatted time string, not null

Throw:

DateTimeException

if an error occurs during printing

public get(field: TemporalField): number source

Gets the value of the specified field as an int.

This queries the date-time for the value for 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.

Specification for implementors

Implementations must check and handle all fields defined in ChronoField. If the field is supported and has an int range, then the value of the field must be returned. If unsupported, then a DateTimeException must be thrown.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom passing this as the argument.

Implementations must not alter either this object.

Override:

TemporalAccessor#get

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

Override:

TemporalAccessor#getLong

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

Return:

number

public hour(): int source

Return:

int

public isAfter(other: OffsetTime): boolean source

Params:

NameTypeAttributeDescription
other OffsetTime

the other time to compare to, not null

Return:

boolean

true if this is after the specified time

Throw:

NullPointerException

if other is null

public isBefore(other: OffsetTime): boolean source

Params:

NameTypeAttributeDescription
other OffsetTime

the other time to compare to, not null

Return:

boolean

true if this point is before the specified time

Throw:

NullPointerException

if other is null

public isEqual(other: OffsetTime): boolean source

Params:

NameTypeAttributeDescription
other OffsetTime

the other time to compare to, not null

Return:

boolean

Throw:

NullPointerException

if other is null

public isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean source

Checks if the specified unit is supported. This checks if the date-time can be queried for the specified unit. If false, then calling the plus and minus methods will throw an exception.

Specification for implementors

Implementations must check and handle all fields defined in ChronoUnit. If the field is supported, then true is returned, otherwise false If the field is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.isSupportedBy(Temporal) passing this as the argument.

Implementations must not alter this object.

Override:

Temporal#isSupported

Params:

NameTypeAttributeDescription
fieldOrUnit TemporalField | TemporalUnit

the field to check, null returns false

Return:

boolean

true if the field is supported on this time, false if not

public minusHours(hours: number): OffsetTime source

Params:

NameTypeAttributeDescription
hours number

Return:

OffsetTime

public minusMinutes(minutes: number): OffsetTime source

Params:

NameTypeAttributeDescription
minutes number

Return:

OffsetTime

public minusNanos(nanos: number): OffsetTime source

Params:

NameTypeAttributeDescription
nanos number

Return:

OffsetTime

public minusSeconds(seconds: number): OffsetTime source

Params:

NameTypeAttributeDescription
seconds number

Return:

OffsetTime

public minute(): int source

Return:

int

public nano(): int source

Return:

int

public offset(): ZoneOffset source

Return:

ZoneOffset

public plusHours(hours: int): OffsetTime source

Params:

NameTypeAttributeDescription
hours int

Return:

OffsetTime

public plusMinutes(minutes: int): OffsetTime source

Params:

NameTypeAttributeDescription
minutes int

Return:

OffsetTime

public plusNanos(nanos: int): OffsetTime source

Params:

NameTypeAttributeDescription
nanos int

Return:

OffsetTime

public plusSeconds(seconds: int): OffsetTime source

Params:

NameTypeAttributeDescription
seconds int

Return:

OffsetTime

public query(query: TemporalQuery): * source

Queries this date-time.

This queries this date-time using the specified query strategy object.

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.

The most common query implementations are method references, such as LocalDate::from and ZoneId::from. Further implementations are on TemporalQueries. Queries may also be defined by applications.

Override:

TemporalAccessor#query

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 range(field: TemporalField): ValueRange source

Gets the range of valid values for the specified field.

All fields can be expressed as a 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.

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.

Specification for implementors

Implementations must check and handle all fields defined in ChronoField. If the field is supported, then the range of the field must be returned. If unsupported, then a DateTimeException must be thrown.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.rangeRefinedBy passing this as the argument.

Implementations must not alter either this object.

Override:

TemporalAccessor#range

Params:

NameTypeAttributeDescription
field TemporalField

the field to query the range for, not null

Return:

ValueRange

the range of valid values for the field, not null

Throw:

DateTimeException

if the range for the field cannot be obtained

public second(): int source

Return:

int

public toJSON(): string source

Return:

string

same as LocalDateTime.toString

public toLocalTime(): LocalTime source

Return:

LocalTime

public toString(): string source

Return:

string

public truncatedTo(unit: TemporalUnit): OffsetTime source

Params:

NameTypeAttributeDescription
unit TemporalUnit

the unit to truncate to, not null

Return:

OffsetTime

a LocalTime based on this time with the time truncated, not null

Throw:

DateTimeException

if unable to truncate

public until(endExclusive: Temporal, unit: TemporalUnit): number source

Calculates the period between this temporal and another temporal in terms of the specified unit. This calculates the period between two temporals in terms of a single unit. The start and end points are this and the specified temporal. The result will be negative if the end is before the start. For example, the period in hours between two temporal objects can be calculated using startTime.until(endTime, HOURS).

The calculation returns a whole number, representing the number of complete units between the two temporals. For example, the period in hours between the times 11:30 and 13:29 will only be one hour as it is one minute short of two hours.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalUnit.between(Temporal, Temporal):

   // these two lines are equivalent
   between = thisUnit.between(start, end);
   between = start.until(end, thisUnit);

The choice should be made based on which makes the code more readable. For example, this method allows the number of days between two dates to be calculated:

   long daysBetween = DAYS.between(start, end);
   // or alternatively
   long daysBetween = start.until(end, DAYS);

Specification for implementors

Implementations must begin by checking to ensure that the input temporal object is of the same observable type as the implementation. They must then perform the calculation for all instances of ChronoUnit. A DateTimeException must be thrown for ChronoUnit instances that are unsupported. If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal) passing this as the first argument and the input temporal as the second argument.

In summary, implementations must behave in a manner equivalent to this code:

  // check input temporal is the same type as this class
  if (unit instanceof ChronoUnit) {
    // if unit is supported, then calculate and return result
    // else throw DateTimeException for unsupported units
  }
  return unit.between(this, endTemporal);

The target object must not be altered by this method.

Override:

Temporal#until

Params:

NameTypeAttributeDescription
endExclusive Temporal

the end time, which is converted to a LocalTime, not null

unit TemporalUnit

the unit to measure the period in, not null

Return:

number

the amount of the period between this time and the end time

Throw:

DateTimeException

if the period cannot be calculated

ArithmeticException

if numeric overflow occurs

public withHour(hour: int): OffsetTime source

Params:

NameTypeAttributeDescription
hour int

Return:

OffsetTime

public withMinute(minute: int): OffsetTime source

Params:

NameTypeAttributeDescription
minute int

Return:

OffsetTime

public withNano(nano: int): OffsetTime source

Params:

NameTypeAttributeDescription
nano int

Return:

OffsetTime

public withOffsetSameInstant(offset: ZoneOffset): OffsetTime source

Params:

NameTypeAttributeDescription
offset ZoneOffset

Return:

OffsetTime

public withOffsetSameLocal(offset: ZoneOffset): OffsetTime source

Params:

NameTypeAttributeDescription
offset ZoneOffset

Return:

OffsetTime

public withSecond(second: int): OffsetTime source

Params:

NameTypeAttributeDescription
second int

Return:

OffsetTime