Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct NodaTime.​ZonedDateTime
Assembly: NodaTime
Implemented Interfaces
- System.​IEquatable`1
- System.​IFormattable
- System.​Xml.​Serialization.​IXmlSerializable
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​IEqualityOperators`3
A <see cref="T:NodaTime.LocalDateTime" /> in a specific time zone and with a particular offset to distinguish between otherwise-ambiguous instants. A <see cref="T:NodaTime.ZonedDateTime" /> is global, in that it maps to a single <see cref="T:NodaTime.Instant" /> .
Remarks
<para>Although <see cref="T:NodaTime.ZonedDateTime" /> includes both local and global concepts, it only supports
duration-based - and not calendar-based - arithmetic. This avoids ambiguities
and skipped date/time values becoming a problem within a series of calculations; instead,
these can be considered just once, at the point of conversion to a <see cref="T:NodaTime.ZonedDateTime" />.
</para> <para>
<c>ZonedDateTime</c> does not implement ordered comparison operators, as there is no obvious natural ordering that works in all cases.
Equality is supported however, requiring equality of zone, calendar and date/time. If you want to sort <c>ZonedDateTime</c>
values, you should explicitly choose one of the orderings provided via the static properties in the
<see cref="T:NodaTime.ZonedDateTime.Comparer" /> nested class (or implement your own comparison).
</para> <para>The default value of this type is 0001-01-01T00:00:00Z (midnight on January 1st, 1 C.E.) in the ISO calendar and the UTC time zone.</para>
Properties
public
Offset
Offset
Gets the offset of the local representation of this value from UTC.
public
DateTimeZone
Zone
Gets the time zone associated with this value.
public
LocalDateTime
LocalDateTime
Gets the local date and time represented by this zoned date and time.
Remarks The returned
<see cref="T:NodaTime.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.
public
CalendarSystem
Calendar
Gets the calendar system associated with this zoned date and time.
public
LocalDate
Date
Gets the local date represented by this zoned date and time.
Remarks The returned <see cref="T:NodaTime.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.
public
LocalTime
TimeOfDay
Gets the time portion of this zoned date and time.
Remarks The returned <see cref="T:NodaTime.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.
public
Era
Era
Gets the era for this zoned date and time.
public
int
Year
Gets the year of this zoned date and time.
Remarks This returns the "absolute year", so, for the ISO calendar,
a value of 0 means 1 BC, for example.
public
int
YearOfEra
Gets the year of this zoned date and time within its era.
public
int
Month
Gets the month of this zoned date and time within the year.
public
int
DayOfYear
Gets the day of this zoned date and time within the year.
public
int
Day
Gets the day of this zoned date and time within the month.
public
IsoDayOfWeek
DayOfWeek
Gets the week day of this zoned date and time expressed as an <see cref="T:NodaTime.IsoDayOfWeek" /> value.
public
int
Hour
Gets the hour of day of this zoned date and time, in the range 0 to 23 inclusive.
public
int
ClockHourOfHalfDay
Gets the hour of the half-day of this zoned date and time, in the range 1 to 12 inclusive.
public
int
Minute
Gets the minute of this zoned date and time, in the range 0 to 59 inclusive.
public
int
Second
Gets the second of this zoned date and time within the minute, in the range 0 to 59 inclusive.
public
int
Millisecond
Gets the millisecond of this zoned date and time within the second, in the range 0 to 999 inclusive.
public
int
TickOfSecond
Gets the tick of this zoned date and time within the second, in the range 0 to 9,999,999 inclusive.
public
long
TickOfDay
Gets the tick of this zoned date and time within the day, in the range 0 to 863,999,999,999 inclusive.
Remarks This is the TickOfDay portion of the contained <see cref="T:NodaTime.OffsetDateTime" /> .
On daylight saving time transition dates, it may not be the same as the number of ticks elapsed since the beginning of the day.
public
int
NanosecondOfSecond
Gets the nanosecond of this zoned date and time within the second, in the range 0 to 999,999,999 inclusive.
public
long
NanosecondOfDay
Gets the nanosecond of this zoned date and time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Remarks This is the NanosecondOfDay portion of the contained <see cref="T:NodaTime.OffsetDateTime" /> .
On daylight saving time transition dates, it may not be the same as the number of nanoseconds elapsed since the beginning of the day.
Methods
public
Instant
ToInstant​()
Converts this value to the instant it represents on the time line.
Returns The instant corresponding to this value.
Remarks
This is always an unambiguous conversion. Any difficulties due to daylight saving
transitions or other changes in time zone are handled when converting from a
<see cref="T:NodaTime.LocalDateTime" /> to a <see cref="T:NodaTime.ZonedDateTime" /> ; the <c>ZonedDateTime</c> remembers
the actual offset from UTC to local time, so it always knows the exact instant represented.
public
ZonedDateTime
WithZone​(DateTimeZone targetZone)
Creates a new <see cref="T:NodaTime.ZonedDateTime" /> representing the same instant in time, in the
same calendar but a different time zone.
Returns A new value in the target time zone.
targetZone
The target time zone to convert to.
public
ZonedDateTime
WithCalendar​(CalendarSystem calendar)
Creates a new ZonedDateTime representing the same physical date, time and offset, but in a different calendar.
The returned ZonedDateTime 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.
Returns The converted ZonedDateTime.
calendar
The calendar system to convert this zoned date and time to.
public
bool
Equals​(ZonedDateTime other)
Indicates whether the current object is equal to another object of the same type.
See the type documentation for a description of equality semantics.
Returns true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
other
An object to compare with this object.
public
bool
Equals​(object obj)
Indicates whether this instance and a specified object are equal.
See the type documentation for a description of equality semantics.
Returns true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.
obj
Another object to compare to.
public
int
GetHashCode​()
Computes the hash code for this instance.
See the type documentation for a description of equality semantics.
Returns A 32-bit signed integer that is the hash code for this instance.
public static
ZonedDateTime
Add​(ZonedDateTime zonedDateTime,
Duration duration)
Adds a duration to a zoned date and time.
Returns A new value with the time advanced by the given duration, in the same calendar system and time zone.
zonedDateTime
The value to add the duration to.
duration
The duration to add
Remarks
This is an alternative way of calling <see cref="M:NodaTime.ZonedDateTime.op_Addition(NodaTime.ZonedDateTime,NodaTime.Duration)" /> .
public
ZonedDateTime
Plus​(Duration duration)
Returns the result of adding a duration to this zoned date and time.
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
duration
The duration to add
Remarks
This is an alternative way of calling <see cref="M:NodaTime.ZonedDateTime.op_Addition(NodaTime.ZonedDateTime,NodaTime.Duration)" /> .
public
ZonedDateTime
PlusHours​(int hours)
Returns the result of adding a increment of hours to this zoned date and time
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
hours
The number of hours to add
public
ZonedDateTime
PlusMinutes​(int minutes)
Returns the result of adding an increment of minutes to this zoned date and time
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
minutes
The number of minutes to add
public
ZonedDateTime
PlusSeconds​(long seconds)
Returns the result of adding an increment of seconds to this zoned date and time
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
seconds
The number of seconds to add
public
ZonedDateTime
PlusMilliseconds​(long milliseconds)
Returns the result of adding an increment of milliseconds to this zoned date and time
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
milliseconds
The number of milliseconds to add
public
ZonedDateTime
PlusTicks​(long ticks)
Returns the result of adding an increment of ticks to this zoned date and time
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
ticks
The number of ticks to add
public
ZonedDateTime
PlusNanoseconds​(long nanoseconds)
Returns the result of adding an increment of nanoseconds to this zoned date and time
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the addition.
nanoseconds
The number of nanoseconds to add
public static
ZonedDateTime
Subtract​(ZonedDateTime zonedDateTime,
Duration duration)
Subtracts a duration from a zoned date and time.
Returns A new value with the time "rewound" by the given duration, in the same calendar system and time zone.
zonedDateTime
The value to subtract the duration from.
duration
The duration to subtract.
Remarks
This is an alternative way of calling <see cref="M:NodaTime.ZonedDateTime.op_Subtraction(NodaTime.ZonedDateTime,NodaTime.Duration)" /> .
public
ZonedDateTime
Minus​(Duration duration)
Returns the result of subtracting a duration from this zoned date and time, for a fluent alternative to
<see cref="M:NodaTime.ZonedDateTime.op_Subtraction(NodaTime.ZonedDateTime,NodaTime.Duration)" />
Returns A new <see cref="T:NodaTime.ZonedDateTime" /> representing the result of the subtraction.
duration
The duration to subtract
public static
Duration
Subtract​(ZonedDateTime end,
ZonedDateTime start)
Subtracts one zoned date and time from another, returning an elapsed duration.
Returns The elapsed duration from <paramref name="start" /> to <paramref name="end" /> .
end
The zoned date and time value to subtract from; if this is later than <paramref name="start" />
then the result will be positive.
start
The zoned date and time to subtract from <paramref name="end" /> .
Remarks
This is an alternative way of calling <see cref="M:NodaTime.ZonedDateTime.op_Subtraction(NodaTime.ZonedDateTime,NodaTime.ZonedDateTime)" /> .
public
Duration
Minus​(ZonedDateTime other)
Returns the result of subtracting another zoned date and time from this one, resulting in the elapsed duration
between the two instants represented in the values.
Returns The elapsed duration from <paramref name="other" /> to this value.
other
The zoned date and time to subtract from this one.
Remarks
This is an alternative way of calling <see cref="M:NodaTime.ZonedDateTime.op_Subtraction(NodaTime.ZonedDateTime,NodaTime.ZonedDateTime)" /> .
public
ZoneInterval
GetZoneInterval​()
Returns the <see cref="T:NodaTime.TimeZones.ZoneInterval" /> containing this value, in the time zone this
value refers to.
Returns The <c>ZoneInterval</c> containing this value.
Remarks
This is simply a convenience method - it is logically equivalent to converting this
value to an <see cref="T:NodaTime.Instant" /> and then asking the appropriate <see cref="T:NodaTime.DateTimeZone" />
for the <c>ZoneInterval</c> containing that instant.
public
bool
IsDaylightSavingTime​()
Indicates whether or not this <see cref="T:NodaTime.ZonedDateTime" /> is in daylight saving time
for its time zone. This is determined by checking the <see cref="P:NodaTime.TimeZones.ZoneInterval.Savings" /> property
of the zone interval containing this value.
Returns <c>true</c> if the zone interval containing this value has a non-zero savings
component; <c>false</c> otherwise.
public
string
ToString​()
Returns a <see cref="T:System.String" /> that represents this instance.
Returns The value of the current instance in the default format pattern ("G"), using the current thread's
culture to obtain a format provider.
public
string
ToString​(string patternText,
System.​IFormatProvider formatProvider)
Formats the value of the current instance using the specified pattern.
Returns A <see cref="T:System.String" /> containing the value of the current instance in the specified format.
patternText
The <see cref="T:System.String" /> specifying the pattern to use,
or null to use the default format pattern ("G").
formatProvider
The <see cref="T:System.IFormatProvider" /> to use when formatting the value,
or null to use the current thread's culture to obtain a format provider.
ToDateTimeOffset​()
Constructs a <see cref="T:System.DateTimeOffset" /> value with the same local time and offset from
UTC as this value.
Returns A <c>DateTimeOffset</c> with the same local date/time and offset as this. The <see cref="T:System.DateTime" /> part of
the result always has a "kind" of Unspecified.
Remarks
<para>
An offset does not convey as much information as a time zone; a <see cref="T:System.DateTimeOffset" />
represents an instant in time along with an associated local time, but it doesn't allow you
to find out what the local time would be for another instant.
</para> <para>
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.
</para> <para>
If the offset has a non-zero second component, this is truncated as <c>DateTimeOffset</c> has an offset
granularity of minutes.
</para> <para>
<see cref="T:System.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 <see cref="T:System.DateTimeOffset" /> may not
match the Year/Month/Day properties of this value.
</para>
public static
ZonedDateTime
FromDateTimeOffset​(System.​DateTimeOffset dateTimeOffset)
Returns a new <see cref="T:NodaTime.ZonedDateTime" /> representing the same instant in time as the given
<see cref="T:System.DateTimeOffset" /> .
The time zone used will be a fixed time zone, which uses the same offset throughout time.
Returns A <see cref="T:NodaTime.ZonedDateTime" /> value representing the same instant in time as the given <see cref="T:System.DateTimeOffset" /> .
dateTimeOffset
Date and time value with an offset.
ToDateTimeUtc​()
Constructs a <see cref="T:System.DateTime" /> from this <see cref="T:NodaTime.ZonedDateTime" /> which has a
<see cref="P:System.DateTime.Kind" /> of <see cref="F:System.DateTimeKind.Utc" /> and represents the same instant of time as
this value rather than the same local time.
Returns A <see cref="T:System.DateTime" /> representation of this value with a "universal" kind, with the same
instant of time as this value.
Remarks
<para>
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.
</para>
ToDateTimeUnspecified​()
Constructs a <see cref="T:System.DateTime" /> from this <see cref="T:NodaTime.ZonedDateTime" /> which has a
<see cref="P:System.DateTime.Kind" /> of <see cref="F:System.DateTimeKind.Unspecified" /> and represents the same local time as
this value rather than the same instant in time.
Returns A <see cref="T:System.DateTime" /> representation of this value with an "unspecified" kind, with the same
local date and time as this value.
Remarks
<para>
<see cref="F:System.DateTimeKind.Unspecified" /> is slightly odd - it can be treated as UTC if you use <see cref="M:System.DateTime.ToLocalTime" />
or as system local time if you use <see cref="M:System.DateTime.ToUniversalTime" />, but it's the only kind which allows
you to construct a <see cref="T:System.DateTimeOffset" /> with an arbitrary offset.
</para> <para>
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.
</para> <para>
<see cref="T:System.DateTime" /> uses the Gregorian calendar by definition, so the value is implicitly converted
to the Gregorian calendar first. The result will be on the same physical date,
but the values returned by the Year/Month/Day properties of the <see cref="T:System.DateTime" /> may not
match the Year/Month/Day properties of this value.
</para>
public
OffsetDateTime
ToOffsetDateTime​()
Constructs an <see cref="T:NodaTime.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.
Returns An OffsetDateTime with the same local date/time and offset as this value.
public
void
Deconstruct​(LocalDateTime& localDateTime,
DateTimeZone& dateTimeZone,
Offset& offset)
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.ZonedDateTime" /> XML serialization to the given <paramref name="xmlSchemaSet" /> .
Returns The qualified name of the schema type that was added to the <paramref name="xmlSchemaSet" /> .
xmlSchemaSet
The XML schema set provided by <see cref="T:System.Xml.Serialization.XmlSchemaExporter" /> .
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object