Home Reference Source
public class | source

OffsetDateTime

Extends:

TemporalAccessorTemporal → OffsetDateTime

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

Static Method Summary

Static Public Methods
public static

from(temporal: TemporaroAccessor): OffsetDateTime

public static

now(clockOrZone: Clock | ZoneId | null): OffsetDateTime

public static
public static

ofDateAndTime(date: *, time: *, offset: *): *

public static

ofDateTime(dateTime: *, offset: *): *

public static
public static

ofNumbers(year: *, month: *, dayOfMonth: *, hour: number, minute: number, second: number, nanoOfSecond: number, offset: *): *

public static

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

Method Summary

Public Methods
public
public
public
public

compareTo(other: *): *

public

dayOfMonth(): number

public

dayOfWeek(): number

public

dayOfYear(): number

public

equals(other: *): boolean

public

format(formatter: DateTimeFormatter): string

public

get(field: *): *

public

getLong(field: *): *

public

hashCode(): number

public

hour(): number

public

isAfter(other: OffsetDateTime): boolean

public

isBefore(other: OffsetDateTime): boolean

public

isEqual(other: OffsetDateTime): boolean

public

isSupported(fieldOrUnit: *): *

public

minusDays(days: int): OffsetTime

public

minusHours(hours: int): OffsetTime

public

minusMinutes(minutes: int): OffsetTime

public

minusMonths(months: int): OffsetTime

public

minusNanos(nanos: int): OffsetTime

public

minusSeconds(seconds: int): OffsetTime

public

minusWeeks(weeks: int): OffsetTime

public

minusYears(years: int): OffsetTime

public

minute(): number

public

month(): {number

public

monthValue(): number

public

nano(): number

public
public

plusDays(days: int): OffsetTime

public

plusHours(hours: int): OffsetTime

public

plusMinutes(minutes: int): OffsetTime

public

plusMonths(months: int): OffsetTime

public

plusNanos(nanos: int): OffsetTime

public

plusSeconds(seconds: int): OffsetTime

public

plusWeeks(weeks: int): OffsetTime

public

plusYears(years: int): OffsetTime

public

query(query: *): *

public

range(field: *): *

public

second(): number

public

toEpochSecond(): number

public
public

toJSON(): string

public
public
public
public
public

toString(): *

public
public
public

until(endExclusive: *, unit: *): *

public

withDayOfMonth(dayOfMonth: int): OffsetDateTime

public

withDayOfYear(dayOfYear: int): OffsetDateTime

public

withHour(hour: int): OffsetDateTime

public

withMinute(minute: int): OffsetDateTime

public

withMonth(month: int): OffsetDateTime

public

withNano(nanoOfSecond: int): OffsetDateTime

public
public
public

withSecond(second: int): OffsetDateTime

public

withYear(year: int): OffsetDateTime

public

year(): number

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: TemporaroAccessor): OffsetDateTime source

Params:

NameTypeAttributeDescription
temporal TemporaroAccessor

Return:

OffsetDateTime

public static now(clockOrZone: Clock | ZoneId | null): OffsetDateTime source

Params:

NameTypeAttributeDescription
clockOrZone Clock | ZoneId | null

Return:

OffsetDateTime

public static of(): OffsetDateTime source

Return:

OffsetDateTime

public static ofDateAndTime(date: *, time: *, offset: *): * source

Params:

NameTypeAttributeDescription
date *
time *
offset *

Return:

*

public static ofDateTime(dateTime: *, offset: *): * source

Params:

NameTypeAttributeDescription
dateTime *
offset *

Return:

*

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

Params:

NameTypeAttributeDescription
instant Instant
zone ZoneId

Return:

OffsetDateTime

public static ofNumbers(year: *, month: *, dayOfMonth: *, hour: number, minute: number, second: number, nanoOfSecond: number, offset: *): * source

Params:

NameTypeAttributeDescription
year *
month *
dayOfMonth *
hour number
  • optional
  • default: 0
minute number
  • optional
  • default: 0
second number
  • optional
  • default: 0
nanoOfSecond number
  • optional
  • default: 0
offset *

Return:

*

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

Params:

NameTypeAttributeDescription
text string
formatter DateTimeFormatter | undefined

Return:

OffsetTime

Public Methods

public adjustInto(temporal: Temporal): Temporal source

Params:

NameTypeAttributeDescription
temporal Temporal

Return:

Temporal

public atZoneSameInstant(zone: ZoneId): ZonedDateTime source

Params:

NameTypeAttributeDescription
zone ZoneId

Return:

ZonedDateTime

public atZoneSimilarLocal(zone: ZoneId): ZonedDateTime source

Params:

NameTypeAttributeDescription
zone ZoneId

Return:

ZonedDateTime

public compareTo(other: *): * source

Params:

NameTypeAttributeDescription
other *

Return:

*

public dayOfMonth(): number source

Return:

number

the day-of-month, from 1 to 31

public dayOfWeek(): number source

Return:

number

the day-of-week, not null

public dayOfYear(): number source

Return:

number

the day-of-year, from 1 to 365, or 366 in a leap year

public equals(other: *): boolean source

Params:

NameTypeAttributeDescription
other *

Return:

boolean

public format(formatter: DateTimeFormatter): string source

Params:

NameTypeAttributeDescription
formatter DateTimeFormatter

Return:

string

public get(field: *): * 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 *

Return:

*

public getLong(field: *): * source

Override:

TemporalAccessor#getLong

Params:

NameTypeAttributeDescription
field *

Return:

*

public hashCode(): number source

Return:

number

public hour(): number source

Return:

number

the hour-of-day, from 0 to 23

public isAfter(other: OffsetDateTime): boolean source

Params:

NameTypeAttributeDescription
other OffsetDateTime

Return:

boolean

public isBefore(other: OffsetDateTime): boolean source

Params:

NameTypeAttributeDescription
other OffsetDateTime

Return:

boolean

public isEqual(other: OffsetDateTime): boolean source

Params:

NameTypeAttributeDescription
other OffsetDateTime

Return:

boolean

public isSupported(fieldOrUnit: *): * 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 *

Return:

*

public minusDays(days: int): OffsetTime source

Params:

NameTypeAttributeDescription
days int

Return:

OffsetTime

public minusHours(hours: int): OffsetTime source

Params:

NameTypeAttributeDescription
hours int

Return:

OffsetTime

public minusMinutes(minutes: int): OffsetTime source

Params:

NameTypeAttributeDescription
minutes int

Return:

OffsetTime

public minusMonths(months: int): OffsetTime source

Params:

NameTypeAttributeDescription
months int

Return:

OffsetTime

public minusNanos(nanos: int): OffsetTime source

Params:

NameTypeAttributeDescription
nanos int

Return:

OffsetTime

public minusSeconds(seconds: int): OffsetTime source

Params:

NameTypeAttributeDescription
seconds int

Return:

OffsetTime

public minusWeeks(weeks: int): OffsetTime source

Params:

NameTypeAttributeDescription
weeks int

Return:

OffsetTime

public minusYears(years: int): OffsetTime source

Params:

NameTypeAttributeDescription
years int

Return:

OffsetTime

public minute(): number source

Return:

number

the minute-of-hour, from 0 to 59

public month(): {number source

Return:

{number

}the month-of-year, not null

See:

public monthValue(): number source

Return:

number

the month-of-year, from 1 to 12

See:

public nano(): number source

Return:

number

the nano-of-second, from 0 to 999,999,999

public offset(): ZoneOffset source

Return:

ZoneOffset

public plusDays(days: int): OffsetTime source

Params:

NameTypeAttributeDescription
days int

Return:

OffsetTime

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 plusMonths(months: int): OffsetTime source

Params:

NameTypeAttributeDescription
months 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 plusWeeks(weeks: int): OffsetTime source

Params:

NameTypeAttributeDescription
weeks int

Return:

OffsetTime

public plusYears(years: int): OffsetTime source

Params:

NameTypeAttributeDescription
years int

Return:

OffsetTime

public query(query: *): * 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 *

Return:

*

public range(field: *): * 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 *

Return:

*

public second(): number source

Return:

number

the second-of-minute, from 0 to 59

public toEpochSecond(): number source

Return:

number

the number of seconds from the epoch of 1970-01-01T00:00:00Z

public toInstant(): Instant source

Return:

Instant

an {@code Instant} representing the same instant, not null

public toJSON(): string source

Return:

string

same as LocalDateTime.toString

public toLocalDate(): LocalDate source

Return:

LocalDate

the date part of this date-time, not null

public toLocalDateTime(): * source

Return:

*

{LocalDateTime}the local date-time part of this date-time, not null

public toLocalTime(): LocalTime source

Return:

LocalTime

the time part of this date-time, not null

public toOffsetTime(): OffsetTime source

Return:

OffsetTime

an OffsetTime representing the time and offset, not null

public toString(): * source

Return:

*

public toZonedDateTime(): * source

Return:

*

{ZonedDateTime}a zoned date-time representing the same local date-time and offset, not null

public truncatedTo(unit: TemporalUnit): OffsetDateTime source

Params:

NameTypeAttributeDescription
unit TemporalUnit

Return:

OffsetDateTime

public until(endExclusive: *, unit: *): * 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 *
unit *

Return:

*

public withDayOfMonth(dayOfMonth: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
dayOfMonth int

Return:

OffsetDateTime

public withDayOfYear(dayOfYear: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
dayOfYear int

Return:

OffsetDateTime

public withHour(hour: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
hour int

Return:

OffsetDateTime

public withMinute(minute: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
minute int

Return:

OffsetDateTime

public withMonth(month: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
month int

Return:

OffsetDateTime

public withNano(nanoOfSecond: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
nanoOfSecond int

Return:

OffsetDateTime

public withOffsetSameInstant(offset: ZoneOffset): OffsetDateTime source

Params:

NameTypeAttributeDescription
offset ZoneOffset

Return:

OffsetDateTime

public withOffsetSameLocal(offset: ZoneOffset): OffsetDateTime source

Params:

NameTypeAttributeDescription
offset ZoneOffset

Return:

OffsetDateTime

public withSecond(second: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
second int

Return:

OffsetDateTime

public withYear(year: int): OffsetDateTime source

Params:

NameTypeAttributeDescription
year int

Return:

OffsetDateTime

public year(): number source

Return:

number

the year, from MIN_YEAR to MAX_YEAR