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
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Assembly: NodaTime.dll
Syntax
public struct OffsetDateTime : IEquatable<OffsetDateTime>
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 an 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()
Currently returns a string representation of this value according to ISO-8601,
extended where necessary to include fractional seconds, and using a colon within the offset
where hour/minute or minute/second separators are required.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override string ToString()
Returns
Type |
Description |
String |
A string representation of this value. |
Overrides
System.ValueType.ToString()
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 . |
Implements
System.IEquatable<T>