OffsetDateTime class
A local date and time in a particular calendar system, combined with an offset from UTC.
A value of this type unambiguously represents both a local time and an instant on the timeline, but does not have a well-defined time zone. This means you cannot reliably know what the local time would be five minutes later, for example. While this doesn't sound terribly useful, it's very common in text representations.
This type is immutable.
- Annotations
-
- @immutable
Constructors
- OffsetDateTime(LocalDateTime localDateTime, Offset offset)
- Constructs a new offset date/time with the given local date and time, and the given offset from UTC.
Properties
- calendar → CalendarSystem
-
Gets the calendar system associated with this offset date and time.
no setter
- calendarDate → LocalDate
-
Gets the nanosecond of this offset date and time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Gets the local date represented by this offset date and time.
no setter
- clockTime → LocalTime
-
Gets the time portion of this offset date and time.
no setter
- dayOfMonth → int
-
Gets the day of this offset date and time within the month.
no setter
- dayOfWeek → DayOfWeek
-
Gets the week day of this offset date and time expressed as an DayOfWeek value.
no setter
- dayOfYear → int
-
Gets the day of this offset date and time within the year.
no setter
- era → Era
-
Gets the era of this offset date and time.
no setter
- hashCode → int
-
Returns a hash code for this offset date and time.
no setteroverride
- hourOf12HourClock → int
-
Gets the hour of the half-day of this offest date and time, in the range 1 to 12 inclusive.
no setter
- hourOfDay → int
-
Gets the hour of day of this offest date and time, in the range 0 to 23 inclusive.
no setter
- inFixedZone → ZonedDateTime
-
Returns this value as a ZonedDateTime.
no setter
- localDateTime → LocalDateTime
-
Returns the local date and time represented within this offset date and time.
final
- microsecondOfSecond → int
-
Gets the microsecond of this offset date and time within the second, in the range 0 to 999,999 inclusive.
no setter
- millisecondOfSecond → int
-
Gets the millisecond of this offset date and time within the second, in the range 0 to 999 inclusive.
no setter
- minuteOfHour → int
-
Gets the minute of this offset date and time, in the range 0 to 59 inclusive.
no setter
- monthOfYear → int
-
Gets the month of this offset date and time within the year.
no setter
- nanosecondOfSecond → int
-
Gets the microsecond of this offset date and time within the day, in the range 0 to 86,399,999,999 inclusive.
Gets the nanosecond of this offset date and time within the second, in the range 0 to 999,999,999 inclusive.
no setter
- offset → Offset
-
Gets the offset from UTC.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secondOfMinute → int
-
Gets the second of this offset date and time within the minute, in the range 0 to 59 inclusive.
no setter
- year → int
-
Gets the year of this offset date and time.
This returns the 'absolute year', so, for the ISO calendar,
a value of 0 means 1 BC, for example.
no setter
- yearOfEra → int
-
Gets the year of this offset date and time within the era.
no setter
Methods
-
add(
Time time) → OffsetDateTime - Returns the result of adding a duration to this offset date and time.
-
adjustDate(
LocalDate adjuster(LocalDate)) → OffsetDateTime - Returns this offset date/time, with the given date adjuster applied to it, maintaining the existing time of day and offset.
-
adjustTime(
LocalTime adjuster(LocalTime)) → OffsetDateTime - Returns this date/time, with the given time adjuster applied to it, maintaining the existing date and offset.
-
equals(
OffsetDateTime other) → bool - Compares two OffsetDateTime values for equality. This requires that the local date/time values be the same (in the same calendar) and the offsets.
-
inZone(
DateTimeZone zone) → ZonedDateTime - Returns this value in ths specified time zone. This method does not expect the offset in the zone to be the same as for the current value; it simply converts this value into an Instant and finds the ZonedDateTime for that instant in the specified zone.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
subtract(
Time time) → OffsetDateTime - Returns the result of subtracting a duration from this offset date and time.
-
timeSince(
OffsetDateTime other) → Time - Returns the result of subtracting this offset date and time from another one, resulting in the elapsed duration between the two instants represented in the values.
-
timeUntil(
OffsetDateTime other) → Time - Returns the result of subtracting another offset date and time from this one, resulting in the elapsed duration between the two instants represented in the values.
-
toInstant(
) → Instant - Converts this offset date and time to an instant in time by subtracting the offset from the local date and time.
-
toOffsetDate(
) → OffsetDate - Constructs a new OffsetDate from the date and offset of this value, but omitting the time-of-day.
-
toOffsetTime(
) → OffsetTime - Constructs a new OffsetTime from the time and offset of this value, but omitting the date.
-
toString(
[String? patternText, Culture? culture]) → String -
Returns a String that represents this instance.
override
-
withCalendar(
CalendarSystem calendar) → OffsetDateTime - Creates a new OffsetDateTime representing the same physical date, time and offset, but in a different calendar. The returned OffsetDateTime is likely to have different date field values to this one. For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
-
withOffset(
Offset offset) → OffsetDateTime - Creates a new OffsetDateTime representing the instant in time in the same calendar, but with a different offset. The local date and time is adjusted accordingly.
Operators
-
operator +(
Time time) → OffsetDateTime - Returns a new OffsetDateTime with the time advanced by the given duration.
-
operator -(
Time time) → OffsetDateTime -
Returns a new OffsetDateTime with the
time
subtracted. -
operator ==(
Object right) → bool -
Implements the operator == (equality).
override
Static Methods
-
difference(
OffsetDateTime end, OffsetDateTime start) → Time -
Subtracts one offset date and time from another, returning an elapsed duration. Equivalent to:
end - start
. -
minus(
OffsetDateTime offsetDateTime, Time time) → OffsetDateTime - Subtracts a duration from an offset date and time.
-
plus(
OffsetDateTime offsetDateTime, Time time) → OffsetDateTime - Adds a duration to an offset date and time.