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
IFormattable
IXmlSerializable
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Assembly: NodaTime.dll
Syntax
[Serializable]
public struct OffsetDateTime : IEquatable<OffsetDateTime>, IFormattable, IXmlSerializable, ISerializable
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
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
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
Day
Gets the day of this offset date and time within the month.
Since 1.0.x
Availability net35-Client, PCL
Declaration
Property Value
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
See Also
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
Era
Gets the era of this offset date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
Property Value
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
Property Value
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
Exceptions
Type |
Condition |
System.InvalidOperationException |
The underlying calendar doesn't use ISO days of the week. |
See Also
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
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
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
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
Offset
Returns the offset from UTC.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Offset Offset { get; }
Property Value
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
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
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
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
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
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
Year
Gets the year of this offset date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
Property Value
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
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
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)
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
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()
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. |
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()
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
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
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
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