Struct OffsetDateTime
Inherited Members
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(OffsetDateTimeTypeConverter))]
public readonly struct OffsetDateTime : IEquatable<OffsetDateTime>, IFormattable, IXmlSerializable
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
Sample snippet
using NodaTime;
using System;
LocalDateTime localDateTime = new LocalDateTime(1985, 10, 26, 1, 18);
Offset offset = Offset.FromHours(-5);
OffsetDateTime offsetDateTime = new OffsetDateTime(localDateTime, offset);
Console.WriteLine(offsetDateTime.LocalDateTime);
Console.WriteLine(offsetDateTime.Offset);
Output:
10/26/1985 01:18:00
-05
Properties
Calendar
Declaration
public readonly CalendarSystem Calendar { get; }
Property Value
Type | Description |
---|---|
CalendarSystem | The calendar system associated with this offset date and time. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly int ClockHourOfHalfDay { get; }
Property Value
Type | Description |
---|---|
Int32 | The hour of the half-day of this offset date and time, in the range 1 to 12 inclusive. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly LocalDate Date { get; }
Property Value
Type | Description |
---|---|
LocalDate | The local date represented by this offset date and time. |
Remarks
Day
Declaration
public readonly int Day { get; }
Property Value
Type | Description |
---|---|
Int32 | The day of this offset date and time within the month. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly IsoDayOfWeek DayOfWeek { get; }
Property Value
Type | Description |
---|---|
IsoDayOfWeek | The week day of this offset date and time expressed as an IsoDayOfWeek . |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly int DayOfYear { get; }
Property Value
Type | Description |
---|---|
Int32 | The day of this offset date and time within the year. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly Era Era { get; }
Property Value
Type | Description |
---|---|
Era | The era of this offset date and time. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly int Hour { get; }
Property Value
Type | Description |
---|---|
Int32 | The hour of day of this offset date and time, in the range 0 to 23 inclusive. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly LocalDateTime LocalDateTime { get; }
Property Value
Type | Description |
---|---|
LocalDateTime | The local date and time represented within this offset date and time. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly int Minute { get; }
Property Value
Type | Description |
---|---|
Int32 | The minute of this offset date and time, in the range 0 to 59 inclusive. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly int Month { get; }
Property Value
Type | Description |
---|---|
Int32 | The month of this offset date and time within the year. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly Offset Offset { get; }
Property Value
Type | Description |
---|---|
Offset | The offset from UTC. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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
Declaration
public readonly LocalTime TimeOfDay { get; }
Property Value
Type | Description |
---|---|
LocalTime | The time portion of this offset date and time. |
Remarks
Year
Declaration
public readonly int Year { get; }
Property Value
Type | Description |
---|---|
Int32 | The year of this offset date and time. |
Remarks
YearOfEra
Declaration
public readonly int YearOfEra { get; }
Property Value
Type | Description |
---|---|
Int32 | The year of this offset date and time within the era. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
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
AddSchema(XmlSchemaSet)
xmlSchemaSet
.
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Type | Name | Description |
---|---|---|
XmlSchemaSet | xmlSchemaSet | The XML schema set provided by XmlSchemaExporter. |
Returns
Type | Description |
---|---|
XmlQualifiedName | The qualified name of the schema type that was added to the xmlSchemaSet . |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
Deconstruct(out LocalDate, out LocalTime, out Offset)
Declaration
public readonly void Deconstruct(out LocalDate localDate, out LocalTime localTime, out Offset offset)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | localDate | The LocalDate component. |
LocalTime | localTime | The LocalTime component. |
Offset | offset | The Offset component. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
Deconstruct(out LocalDateTime, out Offset)
Declaration
public readonly void Deconstruct(out LocalDateTime localDateTime, out Offset offset)
Parameters
Type | Name | Description |
---|---|---|
LocalDateTime | localDateTime | The LocalDateTime component. |
Offset | offset | The Offset component. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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(OffsetDateTime)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public override readonly 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
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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()
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this offset date and time. |
Overrides
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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()
Declaration
public readonly 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.
InZone(DateTimeZone)
Declaration
public readonly ZonedDateTime InZone(DateTimeZone zone)
Parameters
Type | Name | Description |
---|---|---|
DateTimeZone | zone | The time zone of the new value. |
Returns
Type | Description |
---|---|
ZonedDateTime | The instant represented by this value, in the specified time zone. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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(Duration)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Plus(Duration)
Declaration
public readonly 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
PlusHours(Int32)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
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
Subtract(OffsetDateTime, OffsetDateTime)
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
ToDateTimeOffset()
Declaration
public readonly 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.
DateTimeOffset uses the Gregorian calendar by definition, so the value is implicitly converted to the Gregorian calendar first. The result will be the same instant in time (potentially truncated as described above), but the values returned by the Year/Month/Day properties of the DateTimeOffset may not match the Year/Month/Day properties of this value.
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()
Declaration
public readonly Instant ToInstant()
Returns
Type | Description |
---|---|
Instant | The instant represented by this offset date and time |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
ToOffsetDate()
Declaration
public readonly OffsetDate ToOffsetDate()
Returns
Type | Description |
---|---|
OffsetDate | A value representing the date and offset aspects of this value. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
ToOffsetTime()
Declaration
public readonly OffsetTime ToOffsetTime()
Returns
Type | Description |
---|---|
OffsetTime | A value representing the time and offset aspects of this value. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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()
Declaration
public override readonly 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
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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>)
Declaration
public readonly 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
Sample snippet
using NodaTime;
using System;
LocalDateTime localDateTime = new LocalDateTime(1985, 10, 26, 1, 18);
Offset offset = Offset.FromHours(-5);
OffsetDateTime original = new OffsetDateTime(localDateTime, offset);
var dateAdjuster = DateAdjusters.AddPeriod(Period.FromYears(30));
OffsetDateTime updated = original.With(dateAdjuster);
Console.WriteLine(updated.LocalDateTime);
Console.WriteLine(updated.Offset);
Output:
10/26/2015 01:18:00
-05
With(Func<LocalTime, LocalTime>)
Declaration
public readonly 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
Sample snippet
using NodaTime;
using System;
LocalDateTime localDateTime = new LocalDateTime(1985, 10, 26, 1, 18);
Offset offset = Offset.FromHours(-5);
OffsetDateTime original = new OffsetDateTime(localDateTime, offset);
OffsetDateTime updated = original.With(TimeAdjusters.TruncateToHour);
Console.WriteLine(updated.LocalDateTime);
Console.WriteLine(updated.Offset);
Output:
10/26/1985 01:00:00
-05
WithCalendar(CalendarSystem)
Declaration
public readonly 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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
Sample snippet
using NodaTime;
using System;
LocalDateTime localDateTime = new LocalDateTime(1985, 10, 26, 1, 18, CalendarSystem.Iso);
Offset offset = Offset.FromHours(-5);
OffsetDateTime original = new OffsetDateTime(localDateTime, offset);
OffsetDateTime updated = original.WithCalendar(CalendarSystem.Julian);
Console.WriteLine(updated.LocalDateTime.ToString("r", null));
Console.WriteLine(updated.Offset);
Output:
1985-10-13T01:18:00.000000000 (Julian)
-05
WithOffset(Offset)
Declaration
public readonly OffsetDateTime WithOffset(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The new offset to use. |
Returns
Type | Description |
---|---|
OffsetDateTime | The converted OffsetDateTime. |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.
Sample snippet
using NodaTime;
using System;
LocalDateTime localDateTime = new LocalDateTime(1985, 10, 26, 1, 18);
Offset offset = Offset.FromHours(-3);
OffsetDateTime original = new OffsetDateTime(localDateTime, offset);
OffsetDateTime updated = original.WithOffset(Offset.FromHours(-2));
Console.WriteLine(updated.LocalDateTime);
Console.WriteLine(updated.Offset);
Output:
10/26/1985 02:18:00
-02
Operators
Addition(OffsetDateTime, 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
offsetDateTime
.
Equality(OffsetDateTime, OffsetDateTime)
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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
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
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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)
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
offsetDateTime
.
Subtraction(OffsetDateTime, OffsetDateTime)
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
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
IXmlSerializable.ReadXml(XmlReader)
Declaration
readonly void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.WriteXml(XmlWriter)
Declaration
readonly void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer |
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values (including being in the same calendar) and equal offsets from UTC. Ordering between offset date/time values has no natural definition; see OffsetDateTime.Comparer for built-in comparers.
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.