Noda Time
Show / Hide Table of Contents

Struct OffsetDateTime

A local date and time in a particular calendar system, combined with an offset from UTC. This is broadly similar to DateTimeOffset in the BCL.
Implements
IEquatable<OffsetDateTime>
IFormattable
IXmlSerializable
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[Serializable]
public struct OffsetDateTime : IEquatable<OffsetDateTime>, IFormattable, IXmlSerializable, ISerializable
Remarks

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.

Constructors

OffsetDateTime(LocalDateTime, Offset)

Constructs a new offset date/time with the given local date and time, and the given offset from UTC.
Declaration
public OffsetDateTime(LocalDateTime localDateTime, Offset offset)
Parameters
Type Name Description
LocalDateTime localDateTime Local date and time to represent
Offset offset Offset from UTC
Remarks

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.

Properties

Calendar

Gets the calendar system associated with this offset date and time.
Declaration
public CalendarSystem Calendar { get; }
Property Value
Type Description
CalendarSystem The calendar system associated with this offset date and time. (The value returned is never null.)
Remarks

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.

ClockHourOfHalfDay

Gets the hour of the half-day of this offest date and time, in the range 1 to 12 inclusive.
Declaration
public int ClockHourOfHalfDay { get; }
Property Value
Type Description
Int32 The hour of the half-day of this offest date and time, in the range 1 to 12 inclusive.
Remarks

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.

Date

Gets the local date represented by this offset date and time.
Declaration
public LocalDate Date { get; }
Property Value
Type Description
LocalDate The local date represented by this offset date and time.
Remarks
The returned LocalDate will have the same calendar system and return the same values for each of the date-based calendar properties (Year, MonthOfYear and so on), but will not have any offset information.

Day

Gets the day of this offset date and time within the month.
Declaration
public int Day { get; }
Property Value
Type Description
Int32 The day of this offset date and time within the month.
Remarks

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.

DayOfWeek

Gets the week day of this offset date and time expressed as an IsoDayOfWeek value.
Declaration
public IsoDayOfWeek DayOfWeek { get; }
Property Value
Type Description
IsoDayOfWeek The week day of this offset date and time expressed as an IsoDayOfWeek.
Remarks

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.

DayOfYear

Gets the day of this offset date and time within the year.
Declaration
public int DayOfYear { get; }
Property Value
Type Description
Int32 The day of this offset date and time within the year.
Remarks

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.

Era

Gets the era of this offset date and time.
Declaration
public Era Era { get; }
Property Value
Type Description
Era The era of this offset date and time. (The value returned is never null.)
Remarks

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.

Hour

Gets the hour of day of this offest date and time, in the range 0 to 23 inclusive.
Declaration
public int Hour { get; }
Property Value
Type Description
Int32 The hour of day of this offest date and time, in the range 0 to 23 inclusive.
Remarks

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.

LocalDateTime

Returns the local date and time represented within this offset date and time.
Declaration
public LocalDateTime LocalDateTime { get; }
Property Value
Type Description
LocalDateTime The local date and time represented within this offset date and time.
Remarks

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.

Millisecond

Gets the millisecond of this offset date and time within the second, in the range 0 to 999 inclusive.
Declaration
public int Millisecond { get; }
Property Value
Type Description
Int32 The millisecond of this offset date and time within the second, in the range 0 to 999 inclusive.
Remarks

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.

Minute

Gets the minute of this offset date and time, in the range 0 to 59 inclusive.
Declaration
public int Minute { get; }
Property Value
Type Description
Int32 The minute of this offset date and time, in the range 0 to 59 inclusive.
Remarks

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.

Month

Gets the month of this offset date and time within the year.
Declaration
public int Month { get; }
Property Value
Type Description
Int32 The month of this offset date and time within the year.
Remarks

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.

NanosecondOfDay

Gets the nanosecond of this offset date and time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Declaration
public long NanosecondOfDay { get; }
Property Value
Type Description
Int64 The nanosecond of this offset date and time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Remarks

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.

NanosecondOfSecond

Gets the nanosecond of this offset date and time within the second, in the range 0 to 999,999,999 inclusive.
Declaration
public int NanosecondOfSecond { get; }
Property Value
Type Description
Int32 The nanosecond of this offset date and time within the second, in the range 0 to 999,999,999 inclusive.
Remarks

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.

Offset

Gets the offset from UTC.
Declaration
public Offset Offset { get; }
Property Value
Type Description
Offset The offset from UTC.
Remarks

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.

Second

Gets the second of this offset date and time within the minute, in the range 0 to 59 inclusive.
Declaration
public int Second { get; }
Property Value
Type Description
Int32 The second of this offset date and time within the minute, in the range 0 to 59 inclusive.
Remarks

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.

TickOfDay

Gets the tick of this offset date and time within the day, in the range 0 to 863,999,999,999 inclusive.
Declaration
public long TickOfDay { get; }
Property Value
Type Description
Int64 The tick of this offset date and time within the day, in the range 0 to 863,999,999,999 inclusive.
Remarks

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.

TickOfSecond

Gets the tick of this offset date and time within the second, in the range 0 to 9,999,999 inclusive.
Declaration
public int TickOfSecond { get; }
Property Value
Type Description
Int32 The tick of this offset date and time within the second, in the range 0 to 9,999,999 inclusive.
Remarks

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.

TimeOfDay

Gets the time portion of this offset date and time.
Declaration
public LocalTime TimeOfDay { get; }
Property Value
Type Description
LocalTime The time portion of this offset date and time.
Remarks
The returned LocalTime will return the same values for each of the time-based properties (Hour, Minute and so on), but will not have any offset information.

Year

Gets the year of this offset date and time.
Declaration
public int Year { get; }
Property Value
Type Description
Int32 The year of this offset date and time.
Remarks
This returns the "absolute year", so, for the ISO calendar, a value of 0 means 1 BC, for example.

YearOfEra

Gets the year of this offset date and time within the era.
Declaration
public int YearOfEra { get; }
Property Value
Type Description
Int32 The year of this offset date and time within the era.
Remarks

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.

Methods

Add(OffsetDateTime, Duration)

Adds a duration to an offset date and time.
Declaration
public static OffsetDateTime Add(OffsetDateTime offsetDateTime, Duration duration)
Parameters
Type Name Description
OffsetDateTime offsetDateTime The value to add the duration to.
Duration duration The duration to add
Returns
Type Description
OffsetDateTime A new value with the time advanced by the given duration, in the same calendar system and with the same offset.
Remarks
This is an alternative way of calling Addition(OffsetDateTime, Duration).

Equals(OffsetDateTime)

Compares two OffsetDateTime values for equality. This requires that the local date/time values be the same (in the same calendar) and the offsets.
Declaration
public bool Equals(OffsetDateTime other)
Parameters
Type Name Description
OffsetDateTime other The value to compare this offset date/time with.
Returns
Type Description
Boolean True if the given value is another offset date/time equal to this one; false otherwise.
Remarks

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.

Equals(Object)

Compares two OffsetDateTime values for equality. This requires that the local date/time values be the same (in the same calendar) and the offsets.
Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj The object to compare this date with.
Returns
Type Description
Boolean True if the given value is another offset date/time equal to this one; false otherwise.
Overrides
ValueType.Equals(Object)
Remarks

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.

FromDateTimeOffset(DateTimeOffset)

Builds an OffsetDateTime from a BCL DateTimeOffset by converting the DateTime part to a LocalDateTime, and the offset part to an Offset.
Declaration
public static OffsetDateTime FromDateTimeOffset(DateTimeOffset dateTimeOffset)
Parameters
Type Name Description
DateTimeOffset dateTimeOffset DateTimeOffset to convert
Returns
Type Description
OffsetDateTime The converted offset date and time
Remarks

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.

GetHashCode()

Returns a hash code for this offset date and time.
Declaration
public override int GetHashCode()
Returns
Type Description
Int32 A hash code for this offset date and time.
Overrides
ValueType.GetHashCode()
Remarks

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.

InFixedZone()

Returns this value as a ZonedDateTime.
Declaration
public ZonedDateTime InFixedZone()
Returns
Type Description
ZonedDateTime A zoned date/time with the same local time and a fixed time zone using the offset from this value.
Remarks

This method returns a ZonedDateTime with the same local date and time as this value, using a fixed time zone with the same offset as the offset for this value.

Note that because the resulting ZonedDateTime has a fixed time zone, it is generally not useful to use this result for arithmetic operations, as the zone will not adjust to account for daylight savings.

Minus(Duration)

Returns the result of subtracting a duration from this offset date and time, for a fluent alternative to Subtraction(OffsetDateTime, Duration)
Declaration
public OffsetDateTime Minus(Duration duration)
Parameters
Type Name Description
Duration duration The duration to subtract
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the subtraction.
Remarks

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.

Minus(OffsetDateTime)

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.
Declaration
public Duration Minus(OffsetDateTime other)
Parameters
Type Name Description
OffsetDateTime other The offset date and time to subtract from this one.
Returns
Type Description
Duration The elapsed duration from other to this value.
Remarks
This is an alternative way of calling Subtraction(OffsetDateTime, OffsetDateTime).

Plus(Duration)

Returns the result of adding a duration to this offset date and time.
Declaration
public OffsetDateTime Plus(Duration duration)
Parameters
Type Name Description
Duration duration The duration to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks
This is an alternative way of calling Addition(OffsetDateTime, Duration).

PlusHours(Int32)

Returns the result of adding a increment of hours to this zoned date and time
Declaration
public OffsetDateTime PlusHours(int hours)
Parameters
Type Name Description
Int32 hours The number of hours to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks

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.

PlusMilliseconds(Int64)

Returns the result of adding an increment of milliseconds to this zoned date and time
Declaration
public OffsetDateTime PlusMilliseconds(long milliseconds)
Parameters
Type Name Description
Int64 milliseconds The number of milliseconds to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks

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.

PlusMinutes(Int32)

Returns the result of adding an increment of minutes to this zoned date and time
Declaration
public OffsetDateTime PlusMinutes(int minutes)
Parameters
Type Name Description
Int32 minutes The number of minutes to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks

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.

PlusNanoseconds(Int64)

Returns the result of adding an increment of nanoseconds to this zoned date and time
Declaration
public OffsetDateTime PlusNanoseconds(long nanoseconds)
Parameters
Type Name Description
Int64 nanoseconds The number of nanoseconds to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks

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.

PlusSeconds(Int64)

Returns the result of adding an increment of seconds to this zoned date and time
Declaration
public OffsetDateTime PlusSeconds(long seconds)
Parameters
Type Name Description
Int64 seconds The number of seconds to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks

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.

PlusTicks(Int64)

Returns the result of adding an increment of ticks to this zoned date and time
Declaration
public OffsetDateTime PlusTicks(long ticks)
Parameters
Type Name Description
Int64 ticks The number of ticks to add
Returns
Type Description
OffsetDateTime A new OffsetDateTime representing the result of the addition.
Remarks

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.

Subtract(OffsetDateTime, Duration)

Subtracts a duration from an offset date and time.
Declaration
public static OffsetDateTime Subtract(OffsetDateTime offsetDateTime, Duration duration)
Parameters
Type Name Description
OffsetDateTime offsetDateTime The value to subtract the duration from.
Duration duration The duration to subtract.
Returns
Type Description
OffsetDateTime A new value with the time "rewound" by the given duration, in the same calendar system and with the same offset.
Remarks
This is an alternative way of calling Subtraction(OffsetDateTime, Duration).

Subtract(OffsetDateTime, OffsetDateTime)

Subtracts one offset date and time from another, returning an elapsed duration.
Declaration
public static Duration Subtract(OffsetDateTime end, OffsetDateTime start)
Parameters
Type Name Description
OffsetDateTime end The offset date and time value to subtract from; if this is later than start then the result will be positive.
OffsetDateTime start The offset date and time to subtract from end.
Returns
Type Description
Duration The elapsed duration from start to end.
Remarks
This is an alternative way of calling Subtraction(OffsetDateTime, OffsetDateTime).

ToDateTimeOffset()

Returns the BCL DateTimeOffset corresponding to this offset date and time.
Declaration
public DateTimeOffset ToDateTimeOffset()
Returns
Type Description
DateTimeOffset A DateTimeOffset with the same local date/time and offset as this. The DateTime part of the result always has a "kind" of Unspecified.
Remarks

If the date and time is not on a tick boundary (the unit of granularity of DateTime) the value will be truncated towards the start of time.

If the offset has a non-zero second component, this is truncated as DateTimeOffset has an offset granularity of minutes.

Exceptions
Type Condition
InvalidOperationException The date/time is outside the range of DateTimeOffset, or the offset is outside the range of +/-14 hours (the range supported by DateTimeOffset).

ToInstant()

Converts this offset date and time to an instant in time by subtracting the offset from the local date and time.
Declaration
public Instant ToInstant()
Returns
Type Description
Instant The instant represented by this offset date and time
Remarks

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.

ToString()

Returns a String that represents this instance.
Declaration
public override string ToString()
Returns
Type Description
String The value of the current instance in the default format pattern ("G"), using the current thread's culture to obtain a format provider.
Overrides
ValueType.ToString()
Remarks

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.

ToString(String, IFormatProvider)

Formats the value of the current instance using the specified pattern.
Declaration
public string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type Name Description
String patternText The String specifying the pattern to use, or null to use the default format pattern ("G").
IFormatProvider formatProvider The IFormatProvider to use when formatting the value, or null to use the current thread's culture to obtain a format provider.
Returns
Type Description
String A String containing the value of the current instance in the specified format.
Remarks

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.

With(Func<LocalDate, LocalDate>)

Returns this offset date/time, with the given date adjuster applied to it, maintaining the existing time of day and offset.
Declaration
public OffsetDateTime With(Func<LocalDate, LocalDate> adjuster)
Parameters
Type Name Description
Func<LocalDate, LocalDate> adjuster The adjuster to apply.
Returns
Type Description
OffsetDateTime The adjusted offset date/time.
Remarks
If the adjuster attempts to construct an invalid date (such as by trying to set a day-of-month of 30 in February), any exception thrown by that construction attempt will be propagated through this method.
Exceptions
Type Condition
ArgumentNullException adjuster is null.

With(Func<LocalTime, LocalTime>)

Returns this date/time, with the given time adjuster applied to it, maintaining the existing date and offset.
Declaration
public OffsetDateTime With(Func<LocalTime, LocalTime> adjuster)
Parameters
Type Name Description
Func<LocalTime, LocalTime> adjuster The adjuster to apply.
Returns
Type Description
OffsetDateTime The adjusted offset date/time.
Remarks
If the adjuster attempts to construct an invalid time, any exception thrown by that construction attempt will be propagated through this method.
Exceptions
Type Condition
ArgumentNullException adjuster is null.

WithCalendar(CalendarSystem)

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.
Declaration
public OffsetDateTime WithCalendar(CalendarSystem calendar)
Parameters
Type Name Description
CalendarSystem calendar The calendar system to convert this offset date and time to.
Returns
Type Description
OffsetDateTime The converted OffsetDateTime.
Remarks

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.

Exceptions
Type Condition
ArgumentNullException calendar is null.

WithOffset(Offset)

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.
Declaration
public OffsetDateTime WithOffset(Offset offset)
Parameters
Type Name Description
Offset offset The new offset to use.
Returns
Type Description
OffsetDateTime The converted OffsetDateTime.
Remarks

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.

Operators

Addition(OffsetDateTime, Duration)

Returns a new OffsetDateTime with the time advanced by the given duration.
Declaration
public static OffsetDateTime operator +(OffsetDateTime offsetDateTime, Duration duration)
Parameters
Type Name Description
OffsetDateTime offsetDateTime The OffsetDateTime to add the duration to.
Duration duration The duration to add.
Returns
Type Description
OffsetDateTime A new value with the time advanced by the given duration, in the same calendar system and with the same offset.
Remarks
The returned value retains the calendar system and offset of the offsetDateTime.

Equality(OffsetDateTime, OffsetDateTime)

Implements the operator == (equality).
Declaration
public static bool operator ==(OffsetDateTime left, OffsetDateTime right)
Parameters
Type Name Description
OffsetDateTime left The left hand side of the operator.
OffsetDateTime right The right hand side of the operator.
Returns
Type Description
Boolean true if values are equal to each other, otherwise false.
Remarks

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.

Inequality(OffsetDateTime, OffsetDateTime)

Implements the operator != (inequality).
Declaration
public static bool operator !=(OffsetDateTime left, OffsetDateTime right)
Parameters
Type Name Description
OffsetDateTime left The left hand side of the operator.
OffsetDateTime right The right hand side of the operator.
Returns
Type Description
Boolean true if values are not equal to each other, otherwise false.
Remarks

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.

Subtraction(OffsetDateTime, Duration)

Returns a new OffsetDateTime with the duration subtracted.
Declaration
public static OffsetDateTime operator -(OffsetDateTime offsetDateTime, Duration duration)
Parameters
Type Name Description
OffsetDateTime offsetDateTime The value to subtract the duration from.
Duration duration The duration to subtract.
Returns
Type Description
OffsetDateTime A new value with the time "rewound" by the given duration, in the same calendar system and with the same offset.
Remarks
The returned value retains the calendar system and offset of the offsetDateTime.

Subtraction(OffsetDateTime, OffsetDateTime)

Subtracts one OffsetDateTime from another, resulting in the elapsed time between the two values.
Declaration
public static Duration operator -(OffsetDateTime end, OffsetDateTime start)
Parameters
Type Name Description
OffsetDateTime end The offset date and time value to subtract from; if this is later than start then the result will be positive.
OffsetDateTime start The offset date and time to subtract from end.
Returns
Type Description
Duration The elapsed duration from start to end.
Remarks
This is equivalent to end.ToInstant() - start.ToInstant(); in particular:
  • The two values can use different calendar systems
  • The two values can have different UTC offsets

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Implementation of GetObjectData(SerializationInfo, StreamingContext).
Declaration
[SecurityCritical]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info The SerializationInfo to populate with data.
StreamingContext context The destination for this serialization.
Remarks

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.

Exceptions
Type Condition
ArgumentNullException info is null.

IXmlSerializable.GetSchema()

Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type Description
XmlSchema
Remarks

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.

IXmlSerializable.ReadXml(XmlReader)

Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type Name Description
XmlReader reader
Remarks

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.

Exceptions
Type Condition
ArgumentNullException reader is null.

IXmlSerializable.WriteXml(XmlWriter)

Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type Name Description
XmlWriter writer
Remarks

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.

Exceptions
Type Condition
ArgumentNullException writer is null.

Implements

System.IEquatable<T>
System.IFormattable
System.Xml.Serialization.IXmlSerializable
System.Runtime.Serialization.ISerializable
In This Article
Back to top Generated by DocFX