Struct ZonedDateTime
A
LocalDateTime in a specific time zone and with a particular offset to distinguish
between otherwise-ambiguous instants. A
ZonedDateTime is global, in that it maps to a single
Instant.
Since 1.0.x
Availability net35-Client, PCL
Implements
IComparable
IFormattable
IXmlSerializable
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Assembly: NodaTime.dll
Syntax
[Serializable]
public struct ZonedDateTime : IEquatable<ZonedDateTime>, IComparable<ZonedDateTime>, IComparable, IFormattable, IXmlSerializable, ISerializable
Constructors
ZonedDateTime(Instant, DateTimeZone)
Initializes a new instance of the
ZonedDateTime struct in the specified time zone
and the ISO calendar.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime(Instant instant, DateTimeZone zone)
Parameters
ZonedDateTime(Instant, DateTimeZone, CalendarSystem)
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime(Instant instant, DateTimeZone zone, CalendarSystem calendar)
Parameters
Exceptions
Type |
Condition |
ArgumentNullException |
zone or calendar is null |
ZonedDateTime(LocalDateTime, DateTimeZone, Offset)
Initializes a new instance of the
ZonedDateTime struct in the specified time zone
from a given local time and offset. The offset is validated to be correct as part of initialization.
In most cases a local time can only map to a single instant anyway, but the offset is included here for cases
where the local time is ambiguous, usually due to daylight saving transitions.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime(LocalDateTime localDateTime, DateTimeZone zone, Offset offset)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
The local date and time. |
DateTimeZone |
zone |
The time zone. |
Offset |
offset |
The offset between UTC and local time at the desired instant. |
Exceptions
Type |
Condition |
ArgumentException |
offset is not a valid offset at the given
local date and time. |
ArgumentNullException |
zone is null. |
Properties
Calendar
Gets the calendar system associated with this zoned date and time.
Since 1.2.x
Availability net35-Client, PCL
Declaration
public CalendarSystem Calendar { get; }
Property Value
CenturyOfEra
Gets the century within the era of this zoned date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int CenturyOfEra { get; }
Property Value
ClockHourOfHalfDay
Gets the hour of the half-day of this zoned 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 zoned 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 be associated with any particular time zone.
Since 1.1.x
Availability net35-Client, PCL
Declaration
public LocalDate Date { get; }
Property Value
Day
Gets the day of this zoned date and time within the month.
Since 1.0.x
Availability net35-Client, PCL
Declaration
Property Value
DayOfWeek
Gets the week day of this zoned 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 zoned 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 for this zoned date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
Property Value
Hour
Gets the hour of day of this zoned 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 zoned 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
Gets the local date and time represented by this zoned date and time. The returned
LocalDateTime will have the same calendar system and return the same values for
each of the calendar properties (Year, MonthOfYear and so on), but will not be associated with any
particular time zone.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime LocalDateTime { get; }
Property Value
Millisecond
Gets the millisecond of this zoned 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 zoned 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 zoned date and time within the year.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Month { get; }
Property Value
Offset
Gets the offset of the local representation of this value from UTC.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Offset Offset { get; }
Property Value
Second
Gets the second of this zoned 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 zoned 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 zoned 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 zoned 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 be associated with any particular time zone.
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 date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int WeekYear { get; }
Property Value
Year
Gets the year of this zoned date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
Property Value
YearOfCentury
Gets the year of this zoned date and time within its century.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int YearOfCentury { get; }
Property Value
YearOfEra
Gets the year of this zoned date and time within its era.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int YearOfEra { get; }
Property Value
Zone
Gets the time zone associated with this value.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public DateTimeZone Zone { get; }
Property Value
Methods
Add(ZonedDateTime, Duration)
Adds a duration to a zoned date and time. Friendly alternative to operator+()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static ZonedDateTime Add(ZonedDateTime zonedDateTime, Duration duration)
Parameters
Type |
Name |
Description |
ZonedDateTime |
zonedDateTime |
The value to add the duration to. |
Duration |
duration |
The duration to add |
Returns
Type |
Description |
ZonedDateTime |
A new value with the time advanced by the given duration, in the same calendar system and time zone. |
CompareTo(ZonedDateTime)
Indicates whether this date/time is earlier, later or the same as another one.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int CompareTo(ZonedDateTime other)
Parameters
Type |
Name |
Description |
ZonedDateTime |
other |
The other zoned date/time to compare this one with |
Returns
Type |
Description |
Int32 |
A value less than zero if the instant represented by this zoned date/time is earlier than the one in
other ; zero if the instant is the same as the one in other ;
a value greater than zero if the instant is later than the one in other . |
Equals(ZonedDateTime)
Indicates whether the current object is equal to another object of the same type.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public bool Equals(ZonedDateTime other)
Parameters
Type |
Name |
Description |
ZonedDateTime |
other |
An object to compare with this object. |
Returns
Type |
Description |
Boolean |
true if the current object is equal to the other parameter; otherwise, false.
|
Equals(Object)
Indicates whether this instance and a specified object are equal.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
Another object to compare to. |
Returns
Type |
Description |
Boolean |
true if obj and this instance are the same type and represent the same value; otherwise, false.
|
Overrides
System.ValueType.Equals(System.Object)
FromDateTimeOffset(DateTimeOffset)
Returns a new
ZonedDateTime representing the same instant in time as the given
System.DateTimeOffset.
The time zone used will be a fixed time zone, which uses the same offset throughout time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static ZonedDateTime FromDateTimeOffset(DateTimeOffset dateTimeOffset)
Parameters
Type |
Name |
Description |
DateTimeOffset |
dateTimeOffset |
Date and time value with an offset. |
Returns
GetHashCode()
Computes the hash code for this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override int GetHashCode()
Returns
Type |
Description |
Int32 |
A 32-bit signed integer that is the hash code for this instance.
|
Overrides
System.ValueType.GetHashCode()
GetZoneInterval()
Returns the
ZoneInterval containing this value, in the time zone this
value refers to.
Since 1.2.x
Availability net35-Client, PCL
Declaration
public ZoneInterval GetZoneInterval()
Returns
Type |
Description |
ZoneInterval |
The ZoneInterval containing this value. |
IsDaylightSavingTime()
Indicates whether or not this
ZonedDateTime is in daylight saving time
for its time zone. This is determined by checking the
Savings property
of the zone interval containing this value.
Since 1.3.x
Availability net35-Client, PCL
Declaration
public bool IsDaylightSavingTime()
Returns
Type |
Description |
Boolean |
true if the zone interval containing this value has a non-zero savings
component; false otherwise. |
See Also
Minus(Duration)
Returns the result of subtracting a duration from this zoned date and time, for a fluent alternative to operator-()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime Minus(Duration duration)
Parameters
Type |
Name |
Description |
Duration |
duration |
The duration to subtract |
Returns
Plus(Duration)
Returns the result of adding a duration to this zoned date and time, for a fluent alternative to operator+()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime Plus(Duration duration)
Parameters
Type |
Name |
Description |
Duration |
duration |
The duration to add |
Returns
Subtract(ZonedDateTime, Duration)
Subtracts a duration from a zoned date and time. Friendly alternative to operator-()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static ZonedDateTime Subtract(ZonedDateTime zonedDateTime, Duration duration)
Parameters
Type |
Name |
Description |
ZonedDateTime |
zonedDateTime |
The value to subtract the duration from. |
Duration |
duration |
The duration to subtract. |
Returns
Type |
Description |
ZonedDateTime |
A new value with the time "rewound" by the given duration, in the same calendar system and time zone. |
ToDateTimeOffset()
Constructs a System.DateTimeOffset value with the same local time and offset from
UTC as this value.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public DateTimeOffset ToDateTimeOffset()
Returns
Type |
Description |
DateTimeOffset |
A System.DateTimeOffset representation of this value. |
ToDateTimeUnspecified()
Constructs a
System.DateTime from this
ZonedDateTime which has a
System.DateTime.Kind of
System.DateTimeKind.Unspecified and represents the same local time as
this value rather than the same instant in time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public DateTime ToDateTimeUnspecified()
Returns
Type |
Description |
DateTime |
A System.DateTime representation of this value with an "unspecified" kind, with the same
local date and time as this value. |
ToDateTimeUtc()
Constructs a
System.DateTime from this
ZonedDateTime which has a
System.DateTime.Kind of
System.DateTimeKind.Utc and represents the same instant of time as
this value rather than the same local time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public DateTime ToDateTimeUtc()
Returns
Type |
Description |
DateTime |
A System.DateTime representation of this value with a "universal" kind, with the same
instant of time as this value. |
ToInstant()
Converts this value to the instant it represents on the time line.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Instant ToInstant()
Returns
Type |
Description |
Instant |
The instant corresponding to this value. |
ToOffsetDateTime()
Constructs an
OffsetDateTime with the same local date and time, and the same offset
as this zoned date and time, effectively just "removing" the time zone itself.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public OffsetDateTime ToOffsetDateTime()
Returns
Type |
Description |
OffsetDateTime |
An OffsetDateTime with the same local date/time and offset as this value. |
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 |
The value of the current instance in the default format pattern ("G"), using the current thread's
culture to obtain a format provider.
|
Overrides
System.ValueType.ToString()
Formats the value of the current instance using the specified pattern.
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 format pattern ("G").
|
IFormatProvider |
formatProvider |
The System.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 System.String containing the value of the current instance in the specified format.
|
WithZone(DateTimeZone)
Creates a new
ZonedDateTime representing the same instant in time, in the
same calendar but a different time zone.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime WithZone(DateTimeZone targetZone)
Parameters
Type |
Name |
Description |
DateTimeZone |
targetZone |
The target time zone to convert to. |
Returns
Type |
Description |
ZonedDateTime |
A new value in the target time zone. |
Exceptions
Type |
Condition |
ArgumentNullException |
targetZone is null. |
Operators
Addition(ZonedDateTime, Duration)
Returns a new
ZonedDateTime with the time advanced by the given duration. Note that
due to daylight saving time changes this may not advance the local time by the same amount.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static ZonedDateTime operator +(ZonedDateTime zonedDateTime, Duration duration)
Parameters
Returns
Type |
Description |
ZonedDateTime |
A new value with the time advanced by the given duration, in the same calendar system and time zone. |
Equality(ZonedDateTime, ZonedDateTime)
Implements the operator ==.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator ==(ZonedDateTime left, ZonedDateTime right)
Parameters
Returns
Type |
Description |
Boolean |
True if the two operands are equal according to Equals(ZonedDateTime); false otherwise |
GreaterThan(ZonedDateTime, ZonedDateTime)
Compares two
ZonedDateTime values to see if the left one is strictly later than the right
one.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator>(ZonedDateTime lhs, ZonedDateTime rhs)
Parameters
Returns
Type |
Description |
Boolean |
true if the lhs is strictly later than rhs , false otherwise. |
GreaterThanOrEqual(ZonedDateTime, ZonedDateTime)
Compares two
ZonedDateTime values to see if the left one is later than or equal to the right
one.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator >=(ZonedDateTime lhs, ZonedDateTime rhs)
Parameters
Returns
Type |
Description |
Boolean |
true if the lhs is later than or equal to rhs , false otherwise. |
Inequality(ZonedDateTime, ZonedDateTime)
Implements the operator !=.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator !=(ZonedDateTime left, ZonedDateTime right)
Parameters
Returns
Type |
Description |
Boolean |
False if the two operands are equal according to Equals(ZonedDateTime); true otherwise |
LessThan(ZonedDateTime, ZonedDateTime)
Compares two
ZonedDateTime values to see if the left one is strictly earlier than the right
one.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator <(ZonedDateTime lhs, ZonedDateTime rhs)
Parameters
Returns
Type |
Description |
Boolean |
true if the lhs is strictly earlier than rhs , false otherwise. |
LessThanOrEqual(ZonedDateTime, ZonedDateTime)
Compares two
ZonedDateTime values to see if the left one is earlier than or equal to the right
one.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator <=(ZonedDateTime lhs, ZonedDateTime rhs)
Parameters
Returns
Type |
Description |
Boolean |
true if the lhs is earlier than or equal to rhs , false otherwise. |
Subtraction(ZonedDateTime, Duration)
Returns a new ZonedDateTime with the duration subtracted. Note that
due to daylight saving time changes this may not change the local time by the same amount.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static ZonedDateTime operator -(ZonedDateTime zonedDateTime, Duration duration)
Parameters
Type |
Name |
Description |
ZonedDateTime |
zonedDateTime |
The value to subtract the duration from. |
Duration |
duration |
The duration to subtract. |
Returns
Type |
Description |
ZonedDateTime |
A new value with the time "rewound" by the given duration, in the same calendar system and time zone. |
Explicit Interface Implementations
IComparable.CompareTo(Object)
Implementation of System.IComparable.CompareTo(System.Object) to compare two ZonedDateTimes.
Since 1.1.x
Availability net35-Client, PCL
Declaration
int IComparable.CompareTo(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
The object to compare this value with. |
Returns
Type |
Description |
Int32 |
The result of comparing this ZonedDateTime with another one; see CompareTo(ZonedDateTime) for general details.
If obj is null, this method returns a value greater than 0.
|
Exceptions
Type |
Condition |
ArgumentException |
obj is non-null but does not refer to an instance of ZonedDateTime. |
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
[SecurityCritical]
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.IComparable<T>
System.IComparable
System.IFormattable
System.Xml.Serialization.IXmlSerializable
System.Runtime.Serialization.ISerializable