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 System.DateTimeOffset in the BCL.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public OffsetDateTime(LocalDateTime localDateTime, Offset offset)
Parameters
Type Name Description
LocalDateTime localDateTime Local date and time to represent
Offset offset Offset from UTC

Properties

Calendar

Gets the calendar system associated with this local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public CalendarSystem Calendar { get; }
Property Value
Type Description
CalendarSystem

ClockHourOfHalfDay

Gets the hour of the half-day of this date and time, in the range 1 to 12 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int ClockHourOfHalfDay { get; }
Property Value
Type Description
Int32

Date

Gets the local date represented by this offset date and time. 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.
Since 1.1.x
Availability net35-Client, PCL
Declaration
public LocalDate Date { get; }
Property Value
Type Description
LocalDate

Day

Gets the day of this offset date and time within the month.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Day { get; }
Property Value
Type Description
Int32

DayOfWeek

Gets the week day of this offset date and time as a number.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int DayOfWeek { get; }
Property Value
Type Description
Int32
Remarks
For calendars using ISO week days, this gives 1 for Monday to 7 for Sunday.
See Also
IsoDayOfWeek

DayOfYear

Gets the day of this offset date and time within the year.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int DayOfYear { get; }
Property Value
Type Description
Int32

Era

Gets the era of this offset date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Era Era { get; }
Property Value
Type Description
Era

Hour

Gets the hour of day of this offset date and time, in the range 0 to 23 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Hour { get; }
Property Value
Type Description
Int32

IsoDayOfWeek

Gets the week day of this offset date and time expressed as an IsoDayOfWeek value, for calendars which use ISO days of the week.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public IsoDayOfWeek IsoDayOfWeek { get; }
Property Value
Type Description
IsoDayOfWeek
Exceptions
Type Condition
System.InvalidOperationException The underlying calendar doesn't use ISO days of the week.
See Also
DayOfWeek

LocalDateTime

Returns the local date and time represented within this offset date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime LocalDateTime { get; }
Property Value
Type Description
LocalDateTime

Millisecond

Gets the millisecond of this offset date and time within the second, in the range 0 to 999 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Millisecond { get; }
Property Value
Type Description
Int32

Minute

Gets the minute of this offset date and time, in the range 0 to 59 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Minute { get; }
Property Value
Type Description
Int32

Month

Gets the month of this offset date and time within the year.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Month { get; }
Property Value
Type Description
Int32

Offset

Returns the offset from UTC.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Offset Offset { get; }
Property Value
Type Description
Offset

Second

Gets the second of this offset date and time within the minute, in the range 0 to 59 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Second { get; }
Property Value
Type Description
Int32

TickOfDay

Gets the tick of this offset date and time within the day, in the range 0 to 863,999,999,999 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public long TickOfDay { get; }
Property Value
Type Description
Int64

TickOfSecond

Gets the tick of this offset date and time within the second, in the range 0 to 9,999,999 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int TickOfSecond { get; }
Property Value
Type Description
Int32

TimeOfDay

Gets the time portion of this offset date and time. 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.
Since 1.1.x
Availability net35-Client, PCL
Declaration
public LocalTime TimeOfDay { get; }
Property Value
Type Description
LocalTime

WeekOfWeekYear

Gets the week within the WeekYear. See WeekYear for more details.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int WeekOfWeekYear { get; }
Property Value
Type Description
Int32

WeekYear

Gets the "week year" of this offset date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int WeekYear { get; }
Property Value
Type Description
Int32
Remarks

The WeekYear is the year that matches with the WeekOfWeekYear field. In the standard ISO8601 week algorithm, the first week of the year is that in which at least 4 days are in the year. As a result of this definition, day 1 of the first week may be in the previous year. The WeekYear allows you to query the effective year for that day.

For example, January 1st 2011 was a Saturday, so only two days of that week (Saturday and Sunday) were in 2011. Therefore January 1st is part of week 52 of WeekYear 2010. Conversely, December 31st 2012 is a Monday, so is part of week 1 of WeekYear 2013.

Year

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

YearOfCentury

Gets the year of this offset date and time within the century.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int YearOfCentury { get; }
Property Value
Type Description
Int32
Remarks
This always returns a value in the range 0 to 99 inclusive.

YearOfEra

Gets the year of this offset date and time within the era.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int YearOfEra { get; }
Property Value
Type Description
Int32

Methods

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.
Since 1.0.x
Availability net35-Client, PCL
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.

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.
Since 1.0.x
Availability net35-Client, PCL
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
System.ValueType.Equals(System.Object)

FromDateTimeOffset(DateTimeOffset)

Builds an OffsetDateTime from a BCL System.DateTimeOffset by converting the System.DateTime part to a LocalDateTime, and the offset part to an Offset.
Since 1.0.x
Availability net35-Client, PCL
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

GetHashCode()

Returns a hash code for this local date.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override int GetHashCode()
Returns
Type Description
Int32 A hash code for this local date.
Overrides
System.ValueType.GetHashCode()

InFixedZone()

Returns this value as a ZonedDateTime.
Since 1.0.x
Availability net35-Client, PCL
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.

ToDateTimeOffset()

Returns the BCL System.DateTimeOffset corresponding to this offset date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public DateTimeOffset ToDateTimeOffset()
Returns
Type Description
DateTimeOffset A DateTimeOffset with the same local date/time and offset as this. The System.DateTime part of the result always has a "kind" of Unspecified.

ToInstant()

Converts this offset date and time to an instant in time by subtracting the offset from the local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Instant ToInstant()
Returns
Type Description
Instant The instant represented by this offset date and time

ToString()

Returns a System.String that represents this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override string ToString()
Returns
Type Description
String A System.String that represents this instance.
Overrides
System.ValueType.ToString()

ToString(String, IFormatProvider)

Formats the value of the current instance using the specified format.
Since 1.2.x
Availability net35-Client, PCL
Declaration
public string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type Name Description
String patternText The System.String specifying the pattern to use. -or- null to use the default pattern defined for the type of the System.IFormattable implementation.
IFormatProvider formatProvider The System.IFormatProvider to use to format the value. -or- null to obtain the numeric format information from the current locale setting of the operating system.
Returns
Type Description
String A System.String containing the value of the current instance in the specified format.

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.
Since 1.2.x
Availability net35-Client, PCL
Declaration
public OffsetDateTime WithCalendar(CalendarSystem calendarSystem)
Parameters
Type Name Description
CalendarSystem calendarSystem The calendar system to convert this local date to.
Returns
Type Description
OffsetDateTime The converted OffsetDateTime.
Exceptions
Type Condition
System.ArgumentNullException calendarSystem is null.

Operators

Equality(OffsetDateTime, OffsetDateTime)

Implements the operator == (equality).
Since 1.0.x
Availability net35-Client, PCL
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.

Inequality(OffsetDateTime, OffsetDateTime)

Implements the operator != (inequality).
Since 1.0.x
Availability net35-Client, PCL
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.

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Implementation of System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext).
Since 1.2.x
Availability net35-Client
Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info The System.Runtime.Serialization.SerializationInfo to populate with data.
StreamingContext context The destination for this serialization.

IXmlSerializable.GetSchema()

Since 1.2.x
Availability net35-Client, PCL
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type Description
XmlSchema

IXmlSerializable.ReadXml(XmlReader)

Since 1.2.x
Availability net35-Client, PCL
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type Name Description
XmlReader reader

IXmlSerializable.WriteXml(XmlWriter)

Since 1.2.x
Availability net35-Client, PCL
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type Name Description
XmlWriter writer

Implements

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