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
other
ZonedDateTimeAn 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 other
in the sort order.Zero This instance occurs in the same position in the sort order as other
.Greater than zero This instance follows other
in 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
obj
objectAn 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 obj
in the sort order.Zero This instance occurs in the same position in the sort order as obj
.Greater than zero This instance follows obj
in the sort order.
Exceptions
- ArgumentException
obj
is 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
dateTime
DateTimeUnderlying date time.
timeZone
TimeZoneInfoTarget time zone.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When
dateTime
is not valid in the giventimeZone
.
CreateLocal(DateTime)
Creates a new ZonedDateTime instance in Local time zone.
[Pure]
public static ZonedDateTime CreateLocal(DateTime localDateTime)
Parameters
localDateTime
DateTimeUnderlying date time.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When
localDateTime
is 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
timestamp
TimestampUnderlying 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
utcDateTime
DateTimeUnderlying 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
other
ZonedDateTimeAn 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
obj
objectThe object to compare with the current instance.
Returns
- bool
true if
obj
and 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
start
ZonedDateTimeInstance 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
start
ZonedDateTimeStart date time.
units
PeriodUnitsPeriodUnits 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
start
ZonedDateTimeStart date time.
units
PeriodUnitsPeriodUnits 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
weekStart
IsoDayOfWeekFirst 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
day
intDay 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
day
is 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
day
intDay 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
day
is 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
month
IsoMonthOfYearMonth 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
timeOfDay
TimeOfDayTime 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
year
intYear 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
year
is 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
targetTimeZone
TimeZoneInfoTarget 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
dateTime
DateTimeUnderlying date time.
timeZone
TimeZoneInfoTarget time zone.
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when
dateTime
is 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
timeOfDay
TimeOfDayTime 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
a
ZonedDateTimeFirst operand.
b
DurationSecond 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
a
ZonedDateTimeFirst operand.
b
PeriodSecond 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
a
ZonedDateTimeFirst operand.
b
ZonedDateTimeSecond 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
source
ZonedDateTimeValue to convert.
Returns
explicit operator DateTime(ZonedDateTime)
Converts the provided source
to DateTime.
[Pure]
public static explicit operator DateTime(ZonedDateTime source)
Parameters
source
ZonedDateTimeValue to convert.
Returns
operator >(ZonedDateTime, ZonedDateTime)
Checks if a
is greater than b
.
[Pure]
public static bool operator >(ZonedDateTime a, ZonedDateTime b)
Parameters
a
ZonedDateTimeFirst operand.
b
ZonedDateTimeSecond operand.
Returns
- bool
true when
a
is 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
a
ZonedDateTimeFirst operand.
b
ZonedDateTimeSecond operand.
Returns
- bool
true when
a
is 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
a
ZonedDateTimeFirst operand.
b
ZonedDateTimeSecond 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
a
ZonedDateTimeFirst operand.
b
ZonedDateTimeSecond operand.
Returns
- bool
true when
a
is 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
a
ZonedDateTimeFirst operand.
b
ZonedDateTimeSecond operand.
Returns
- bool
true when
a
is 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
a
ZonedDateTimeFirst operand.
b
DurationSecond 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
a
ZonedDateTimeFirst operand.
b
PeriodSecond operand.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When result is not valid in the given TimeZone.