Added in API level 26

OffsetDateTime

class OffsetDateTime : Comparable<OffsetDateTime!>, Serializable, Temporal, TemporalAdjuster
kotlin.Any
   ↳ java.time.OffsetDateTime

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

OffsetDateTime is an immutable representation of a date-time with an offset. This class stores all date and time fields, to a precision of nanoseconds, as well as the offset from UTC/Greenwich. For example, the value "2nd October 2007 at 13:45:30.123456789 +02:00" can be stored in an OffsetDateTime.

OffsetDateTime, java.time.ZonedDateTime and java.time.Instant all store an instant on the time-line to nanosecond precision. Instant is the simplest, simply representing the instant. OffsetDateTime adds to the instant the offset from UTC/Greenwich, which allows the local date-time to be obtained. ZonedDateTime adds full time-zone rules.

It is intended that ZonedDateTime or Instant is used to model data in simpler applications. This class may be used when modeling date-time concepts in more detail, or when communicating to a database or in a network protocol.

This is a value-based<> class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. The equals method should be used for comparisons.

Summary

Public methods
Temporal!
adjustInto(temporal: Temporal!)

Adjusts the specified temporal object to have the same offset, date and time as this object.

ZonedDateTime!

Combines this date-time with a time-zone to create a ZonedDateTime ensuring that the result has the same instant.

ZonedDateTime!

Combines this date-time with a time-zone to create a ZonedDateTime trying to keep the same local date and time.

Int

Compares this date-time to another date-time.

Boolean
equals(other: Any?)

Checks if this date-time is equal to another date-time.

String!

Formats this date-time using the specified formatter.

static OffsetDateTime!
from(temporal: TemporalAccessor!)

Obtains an instance of OffsetDateTime from a temporal object.

Int
get(field: TemporalField!)

Gets the value of the specified field from this date-time as an int.

Int

Gets the day-of-month field.

DayOfWeek!

Gets the day-of-week field, which is an enum DayOfWeek.

Int

Gets the day-of-year field.

Int

Gets the hour-of-day field.

Long

Gets the value of the specified field from this date-time as a long.

Int

Gets the minute-of-hour field.

Month!

Gets the month-of-year field using the Month enum.

Int

Gets the month-of-year field from 1 to 12.

Int

Gets the nano-of-second field.

ZoneOffset!

Gets the zone offset, such as '+01:00'.

Int

Gets the second-of-minute field.

Int

Gets the year field.

Int

A hash code for this date-time.

Boolean

Checks if the instant of this date-time is after that of the specified date-time.

Boolean

Checks if the instant of this date-time is before that of the specified date-time.

Boolean

Checks if the instant of this date-time is equal to that of the specified date-time.

Boolean

Checks if the specified field is supported.

Boolean

Checks if the specified unit is supported.

OffsetDateTime!
minus(amountToSubtract: TemporalAmount!)

Returns a copy of this date-time with the specified amount subtracted.

OffsetDateTime!
minus(amountToSubtract: Long, unit: TemporalUnit!)

Returns a copy of this date-time with the specified amount subtracted.

OffsetDateTime!
minusDays(days: Long)

Returns a copy of this OffsetDateTime with the specified number of days subtracted.

OffsetDateTime!
minusHours(hours: Long)

Returns a copy of this OffsetDateTime with the specified number of hours subtracted.

OffsetDateTime!
minusMinutes(minutes: Long)

Returns a copy of this OffsetDateTime with the specified number of minutes subtracted.

OffsetDateTime!
minusMonths(months: Long)

Returns a copy of this OffsetDateTime with the specified number of months subtracted.

OffsetDateTime!
minusNanos(nanos: Long)

Returns a copy of this OffsetDateTime with the specified number of nanoseconds subtracted.

OffsetDateTime!
minusSeconds(seconds: Long)

Returns a copy of this OffsetDateTime with the specified number of seconds subtracted.

OffsetDateTime!
minusWeeks(weeks: Long)

Returns a copy of this OffsetDateTime with the specified number of weeks subtracted.

OffsetDateTime!
minusYears(years: Long)

Returns a copy of this OffsetDateTime with the specified number of years subtracted.

static OffsetDateTime!
now()

Obtains the current date-time from the system clock in the default time-zone.

static OffsetDateTime!
now(clock: Clock!)

Obtains the current date-time from the specified clock.

static OffsetDateTime!
now(zone: ZoneId!)

Obtains the current date-time from the system clock in the specified time-zone.

static OffsetDateTime!
of(year: Int, month: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanoOfSecond: Int, offset: ZoneOffset!)

Obtains an instance of OffsetDateTime from a year, month, day, hour, minute, second, nanosecond and offset.

static OffsetDateTime!
of(date: LocalDate!, time: LocalTime!, offset: ZoneOffset!)

Obtains an instance of OffsetDateTime from a date, time and offset.

static OffsetDateTime!
of(dateTime: LocalDateTime!, offset: ZoneOffset!)

Obtains an instance of OffsetDateTime from a date-time and offset.

static OffsetDateTime!
ofInstant(instant: Instant!, zone: ZoneId!)

Obtains an instance of OffsetDateTime from an Instant and zone ID.

static OffsetDateTime!

Obtains an instance of OffsetDateTime from a text string such as 2007-12-03T10:15:30+01:00.

static OffsetDateTime!
parse(text: CharSequence!, formatter: DateTimeFormatter!)

Obtains an instance of OffsetDateTime from a text string using a specific formatter.

OffsetDateTime!
plus(amountToAdd: TemporalAmount!)

Returns a copy of this date-time with the specified amount added.

OffsetDateTime!
plus(amountToAdd: Long, unit: TemporalUnit!)

Returns a copy of this date-time with the specified amount added.

OffsetDateTime!
plusDays(days: Long)

Returns a copy of this OffsetDateTime with the specified number of days added.

OffsetDateTime!
plusHours(hours: Long)

Returns a copy of this OffsetDateTime with the specified number of hours added.

OffsetDateTime!
plusMinutes(minutes: Long)

Returns a copy of this OffsetDateTime with the specified number of minutes added.

OffsetDateTime!
plusMonths(months: Long)

Returns a copy of this OffsetDateTime with the specified number of months added.

OffsetDateTime!
plusNanos(nanos: Long)

Returns a copy of this OffsetDateTime with the specified number of nanoseconds added.

OffsetDateTime!
plusSeconds(seconds: Long)

Returns a copy of this OffsetDateTime with the specified number of seconds added.

OffsetDateTime!
plusWeeks(weeks: Long)

Returns a copy of this OffsetDateTime with the specified number of weeks added.

OffsetDateTime!
plusYears(years: Long)

Returns a copy of this OffsetDateTime with the specified number of years added.

R
query(query: TemporalQuery<R>!)

Queries this date-time using the specified query.

ValueRange!

Gets the range of valid values for the specified field.

static Comparator<OffsetDateTime!>!

Gets a comparator that compares two OffsetDateTime instances based solely on the instant.

Long

Converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z.

Instant!

Converts this date-time to an Instant.

LocalDate!

Gets the LocalDate part of this date-time.

LocalDateTime!

Gets the LocalDateTime part of this date-time.

LocalTime!

Gets the LocalTime part of this date-time.

OffsetTime!

Converts this date-time to an OffsetTime.

String

Outputs this date-time as a String, such as 2007-12-03T10:15:30+01:00.

ZonedDateTime!

Converts this date-time to a ZonedDateTime using the offset as the zone ID.

OffsetDateTime!

Returns a copy of this OffsetDateTime with the time truncated.

Long
until(endExclusive: Temporal!, unit: TemporalUnit!)

Calculates the amount of time until another date-time in terms of the specified unit.

OffsetDateTime!
with(adjuster: TemporalAdjuster!)

Returns an adjusted copy of this date-time.

OffsetDateTime!
with(field: TemporalField!, newValue: Long)

Returns a copy of this date-time with the specified field set to a new value.

OffsetDateTime!
withDayOfMonth(dayOfMonth: Int)

Returns a copy of this OffsetDateTime with the day-of-month altered.

OffsetDateTime!
withDayOfYear(dayOfYear: Int)

Returns a copy of this OffsetDateTime with the day-of-year altered.

OffsetDateTime!
withHour(hour: Int)

Returns a copy of this OffsetDateTime with the hour-of-day altered.

OffsetDateTime!
withMinute(minute: Int)

Returns a copy of this OffsetDateTime with the minute-of-hour altered.

OffsetDateTime!
withMonth(month: Int)

Returns a copy of this OffsetDateTime with the month-of-year altered.

OffsetDateTime!
withNano(nanoOfSecond: Int)

Returns a copy of this OffsetDateTime with the nano-of-second altered.

OffsetDateTime!

Returns a copy of this OffsetDateTime with the specified offset ensuring that the result is at the same instant.

OffsetDateTime!

Returns a copy of this OffsetDateTime with the specified offset ensuring that the result has the same local date-time.

OffsetDateTime!
withSecond(second: Int)

Returns a copy of this OffsetDateTime with the second-of-minute altered.

OffsetDateTime!
withYear(year: Int)

Returns a copy of this OffsetDateTime with the year altered.

Properties
static OffsetDateTime!

The maximum supported OffsetDateTime, '+999999999-12-31T23:59:59.

static OffsetDateTime!

The minimum supported OffsetDateTime, '-999999999-01-01T00:00:00+18:00'.

Public methods

adjustInto

Added in