Struct ZonedDateTime
Represents a DateTime with time zone.
public readonly struct ZonedDateTime : IEquatable<ZonedDateTime>, IComparable<ZonedDateTime>, IComparable
- Implements
- Inherited Members
Properties
DayOfMonth
Day of month component.
public int DayOfMonth { get; }
Property Value
DayOfWeek
Day of week component.
public IsoDayOfWeek DayOfWeek { get; }
Property Value
DayOfYear
Day of year component.
public int DayOfYear { get; }
Property Value
IsAmbiguous
Checks whether or not this date time is ambiguous.
public bool IsAmbiguous { get; }
Property Value
IsInDaylightSavingTime
Checks whether or not this date time is in daylight saving time.
public bool IsInDaylightSavingTime { get; }
Property Value
IsLocal
Checks whether or not the TimeZone is local.
public bool IsLocal { get; }
Property Value
IsUtc
Checks whether or not the TimeZone is UTC.
public bool IsUtc { get; }
Property Value
Month
Month component.
public IsoMonthOfYear Month { get; }
Property Value
TimeOfDay
TimeOfDay component.
public TimeOfDay TimeOfDay { get; }
Property Value
TimeZone
Time zone of this date time.
public TimeZoneInfo TimeZone { get; }
Property Value
Timestamp
Timestamp equivalent to this date time.
public Timestamp Timestamp { get; }
Property Value
UtcOffset
Calculates the UTC offset of this date time.
public Duration UtcOffset { get; }
Property Value
Value
Underlying DateTime value.
public DateTime Value { get; }
Property Value
Year
Year component.
public int Year { get; }
Property Value
Methods
Add(Duration)
Creates a new ZonedDateTime instance by adding value to this instance.
[Pure]
public ZonedDateTime Add(Duration value)
Parameters
Returns
- ZonedDateTime
New ZonedDateTime instance.
Add(Period)
Creates a new ZonedDateTime instance by adding value to this instance.
[Pure]
public ZonedDateTime Add(Period value)
Parameters
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When result is not valid in this instance's TimeZone.
CompareTo(ZonedDateTime)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
[Pure]
public int CompareTo(ZonedDateTime other)
Parameters
otherZonedDateTimeAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
CompareTo(object?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
[Pure]
public int CompareTo(object? obj)
Parameters
objobjectAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis not the same type as this instance.
Create(DateTime, TimeZoneInfo)
Creates a new ZonedDateTime instance.
[Pure]
public static ZonedDateTime Create(DateTime dateTime, TimeZoneInfo timeZone)
Parameters
dateTimeDateTimeUnderlying date time.
timeZoneTimeZoneInfoTarget time zone.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When
dateTimeis not valid in the giventimeZone.
CreateLocal(DateTime)
Creates a new ZonedDateTime instance in Local time zone.
[Pure]
public static ZonedDateTime CreateLocal(DateTime localDateTime)
Parameters
localDateTimeDateTimeUnderlying date time.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When
localDateTimeis not valid in Local time zone.
CreateUtc(Timestamp)
Creates a new ZonedDateTime instance in Utc time zone.
[Pure]
public static ZonedDateTime CreateUtc(Timestamp timestamp)
Parameters
timestampTimestampUnderlying timestamp.
Returns
- ZonedDateTime
New ZonedDateTime instance.
CreateUtc(DateTime)
Creates a new ZonedDateTime instance in Utc time zone.
[Pure]
public static ZonedDateTime CreateUtc(DateTime utcDateTime)
Parameters
utcDateTimeDateTimeUnderlying date time.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Equals(ZonedDateTime)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(ZonedDateTime other)
Parameters
otherZonedDateTimeAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetDay()
Creates a new ZonedDay instance that contains this instance.
[Pure]
public ZonedDay GetDay()
Returns
GetDurationOffset(ZonedDateTime)
Calculates a difference in Duration between this instance and the start instance,
where this instance is treated as the end of the range.
[Pure]
public Duration GetDurationOffset(ZonedDateTime start)
Parameters
startZonedDateTimeInstance to subtract.
Returns
GetGreedyPeriodOffset(ZonedDateTime, PeriodUnits)
Creates a new Period instance by calculating a difference between this instance and
the start instance, where this instance is treated as the end of the range,
using the specified units.
[Pure]
public Period GetGreedyPeriodOffset(ZonedDateTime start, PeriodUnits units)
Parameters
startZonedDateTimeStart date time.
unitsPeriodUnitsPeriodUnits to include in the calculated difference.
Returns
Remarks
Greedy Period may contain components with negative values.
GetHashCode()
Returns the hash code for this instance.
[Pure]
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetMonth()
Creates a new ZonedMonth instance that contains this instance.
[Pure]
public ZonedMonth GetMonth()
Returns
- ZonedMonth
New ZonedMonth instance.
GetOppositeAmbiguousDateTime()
Attempts to create a new ZonedDateTime instance by calculating the other version of an ambiguous value, if this instance represents an ambiguous date time in its TimeZone.
[Pure]
public ZonedDateTime? GetOppositeAmbiguousDateTime()
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when this instance is not ambiguous.
GetPeriodOffset(ZonedDateTime, PeriodUnits)
Creates a new Period instance by calculating a difference between this instance and
the start instance, where this instance is treated as the end of the range,
using the specified units.
[Pure]
public Period GetPeriodOffset(ZonedDateTime start, PeriodUnits units)
Parameters
startZonedDateTimeStart date time.
unitsPeriodUnitsPeriodUnits to include in the calculated difference.
Returns
GetWeek(IsoDayOfWeek)
Creates a new ZonedWeek instance that contains this instance.
[Pure]
public ZonedWeek GetWeek(IsoDayOfWeek weekStart = IsoDayOfWeek.Monday)
Parameters
weekStartIsoDayOfWeekFirst day of the week.
Returns
GetYear()
Creates a new ZonedYear instance that contains this instance.
[Pure]
public ZonedYear GetYear()
Returns
SetDayOfMonth(int)
Creates a new ZonedDateTime instance by setting the DayOfMonth component in this instance.
[Pure]
public ZonedDateTime SetDayOfMonth(int day)
Parameters
dayintDay of month to set.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Remarks
Result may end up with modified components other than the day of month, if it lands in the range of invalid values of this instance's TimeZone.
Exceptions
- ArgumentOutOfRangeException
When
dayis not valid for the current month.
SetDayOfYear(int)
Creates a new ZonedDateTime instance by setting the DayOfYear component in this instance.
[Pure]
public ZonedDateTime SetDayOfYear(int day)
Parameters
dayintDay of year to set.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Remarks
Result may end up with modified components other than the day of year, if it lands in the range of invalid values of this instance's TimeZone.
Exceptions
- ArgumentOutOfRangeException
When
dayis not valid for the current year.
SetMonth(IsoMonthOfYear)
Creates a new ZonedDateTime instance by setting the Month component in this instance.
[Pure]
public ZonedDateTime SetMonth(IsoMonthOfYear month)
Parameters
monthIsoMonthOfYearMonth to set.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Remarks
Result may end up with modified components other than the month, if it lands in the range of invalid values of this instance's TimeZone.
SetTimeOfDay(TimeOfDay)
Creates a new ZonedDateTime instance by setting the TimeOfDay component in this instance.
[Pure]
public ZonedDateTime SetTimeOfDay(TimeOfDay timeOfDay)
Parameters
timeOfDayTimeOfDayTime of day to set.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When result is not valid in this instance's TimeZone.
SetYear(int)
Creates a new ZonedDateTime instance by setting the Year component in this instance.
[Pure]
public ZonedDateTime SetYear(int year)
Parameters
yearintYear to set.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Remarks
Result may end up with modified components other than the year, if it lands in the range of invalid values of this instance's TimeZone.
Exceptions
- ArgumentOutOfRangeException
When
yearis not valid.
Subtract(Duration)
Creates a new ZonedDateTime instance by subtracting value from this instance.
[Pure]
public ZonedDateTime Subtract(Duration value)
Parameters
Returns
- ZonedDateTime
New ZonedDateTime instance.
Subtract(Period)
Creates a new ZonedDateTime instance by subtracting value from this instance.
[Pure]
public ZonedDateTime Subtract(Period value)
Parameters
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When result is not valid in this instance's TimeZone.
ToLocalTimeZone()
Creates a new ZonedDateTime in Local time zone from this instance.
[Pure]
public ZonedDateTime ToLocalTimeZone()
Returns
- ZonedDateTime
New ZonedDateTime instance.
ToString()
Returns a string representation of this ZonedDateTime instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
ToTimeZone(TimeZoneInfo)
Creates a new ZonedDateTime in the targetTimeZone from this instance.
[Pure]
public ZonedDateTime ToTimeZone(TimeZoneInfo targetTimeZone)
Parameters
targetTimeZoneTimeZoneInfoTarget time zone.
Returns
- ZonedDateTime
New ZonedDateTime instance.
ToUtcTimeZone()
Creates a new ZonedDateTime in Utc time zone from this instance.
[Pure]
public ZonedDateTime ToUtcTimeZone()
Returns
- ZonedDateTime
New ZonedDateTime instance.
TryAdd(Period)
Attempts to create a new ZonedDateTime instance by adding value to this instance.
[Pure]
public ZonedDateTime? TryAdd(Period value)
Parameters
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when result is not valid in this instance's TimeZone.
TryCreate(DateTime, TimeZoneInfo)
Attempts to create a new ZonedDateTime instance.
[Pure]
public static ZonedDateTime? TryCreate(DateTime dateTime, TimeZoneInfo timeZone)
Parameters
dateTimeDateTimeUnderlying date time.
timeZoneTimeZoneInfoTarget time zone.
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when
dateTimeis not valid in the giventimeZone.
TrySetTimeOfDay(TimeOfDay)
Attempts to create a new ZonedDateTime instance by setting the TimeOfDay component in this instance.
[Pure]
public ZonedDateTime? TrySetTimeOfDay(TimeOfDay timeOfDay)
Parameters
timeOfDayTimeOfDayTime of day to set.
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when result is not valid in this instance's TimeZone.
TrySubtract(Period)
Attempts to create a new ZonedDateTime instance by subtracting value from this instance.
[Pure]
public ZonedDateTime? TrySubtract(Period value)
Parameters
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when result is not valid in this instance's TimeZone.
Operators
operator +(ZonedDateTime, Duration)
Creates a new ZonedDateTime instance by adding a and b together.
[Pure]
public static ZonedDateTime operator +(ZonedDateTime a, Duration b)
Parameters
aZonedDateTimeFirst operand.
bDurationSecond operand.
Returns
- ZonedDateTime
New ZonedDateTime instance.
operator +(ZonedDateTime, Period)
Creates a new ZonedDateTime instance by adding a and b together.
[Pure]
public static ZonedDateTime operator +(ZonedDateTime a, Period b)
Parameters
aZonedDateTimeFirst operand.
bPeriodSecond operand.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When result is not valid in the given TimeZone.
operator ==(ZonedDateTime, ZonedDateTime)
Checks if a is equal to b.
[Pure]
public static bool operator ==(ZonedDateTime a, ZonedDateTime b)
Parameters
aZonedDateTimeFirst operand.
bZonedDateTimeSecond operand.
Returns
- bool
true when operands are equal, otherwise false.
explicit operator Timestamp(ZonedDateTime)
Converts the provided source to Timestamp.
[Pure]
public static explicit operator Timestamp(ZonedDateTime source)
Parameters
sourceZonedDateTimeValue to convert.
Returns
explicit operator DateTime(ZonedDateTime)
Converts the provided source to DateTime.
[Pure]
public static explicit operator DateTime(ZonedDateTime source)
Parameters
sourceZonedDateTimeValue to convert.
Returns
operator >(ZonedDateTime, ZonedDateTime)
Checks if a is greater than b.
[Pure]
public static bool operator >(ZonedDateTime a, ZonedDateTime b)
Parameters
aZonedDateTimeFirst operand.
bZonedDateTimeSecond operand.
Returns
- bool
true when
ais greater thanb, otherwise false.
operator >=(ZonedDateTime, ZonedDateTime)
Checks if a is greater than or equal to b.
[Pure]
public static bool operator >=(ZonedDateTime a, ZonedDateTime b)
Parameters
aZonedDateTimeFirst operand.
bZonedDateTimeSecond operand.
Returns
- bool
true when
ais greater than or equal tob, otherwise false.
operator !=(ZonedDateTime, ZonedDateTime)
Checks if a is not equal to b.
[Pure]
public static bool operator !=(ZonedDateTime a, ZonedDateTime b)
Parameters
aZonedDateTimeFirst operand.
bZonedDateTimeSecond operand.
Returns
- bool
true when operands are not equal, otherwise false.
operator <(ZonedDateTime, ZonedDateTime)
Checks if a is less than b.
[Pure]
public static bool operator <(ZonedDateTime a, ZonedDateTime b)
Parameters
aZonedDateTimeFirst operand.
bZonedDateTimeSecond operand.
Returns
- bool
true when
ais less thanb, otherwise false.
operator <=(ZonedDateTime, ZonedDateTime)
Checks if a is less than or equal to b.
[Pure]
public static bool operator <=(ZonedDateTime a, ZonedDateTime b)
Parameters
aZonedDateTimeFirst operand.
bZonedDateTimeSecond operand.
Returns
- bool
true when
ais less than or equal tob, otherwise false.
operator -(ZonedDateTime, Duration)
Creates a new ZonedDateTime instance by subtracting b from a.
[Pure]
public static ZonedDateTime operator -(ZonedDateTime a, Duration b)
Parameters
aZonedDateTimeFirst operand.
bDurationSecond operand.
Returns
- ZonedDateTime
New ZonedDateTime instance.
operator -(ZonedDateTime, Period)
Creates a new ZonedDateTime instance by subtracting b from a.
[Pure]
public static ZonedDateTime operator -(ZonedDateTime a, Period b)
Parameters
aZonedDateTimeFirst operand.
bPeriodSecond operand.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When result is not valid in the given TimeZone.