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 System.​DateTimeOffset
Assembly: System.Runtime
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC).
Fields and Constants
public static readonly
DateTimeOffset
MaxValue
Represents the greatest possible value of <see cref="T:System.DateTimeOffset" /> . This field is read-only.
public static readonly
DateTimeOffset
MinValue
Represents the earliest possible <see cref="T:System.DateTimeOffset" /> value. This field is read-only.
public static readonly
DateTimeOffset
UnixEpoch
The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 1970, in the Gregorian calendar. <see cref="F:System.DateTimeOffset.UnixEpoch" /> defines the point in time when Unix time is equal to 0.
Properties
public
DateTime
Date
Gets a <see cref="T:System.DateTime" /> value that represents the date component of the current <see cref="T:System.DateTimeOffset" /> object.
public
DateTime
DateTime
Gets a <see cref="T:System.DateTime" /> value that represents the date and time of the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Day
Gets the day of the month represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
DayOfWeek
DayOfWeek
Gets the day of the week represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
int
DayOfYear
Gets the day of the year represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Hour
Gets the hour component of the time represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
DateTime
LocalDateTime
Gets a <see cref="T:System.DateTime" /> value that represents the local date and time of the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Microsecond
Gets the microsecond component of the time represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Millisecond
Gets the millisecond component of the time represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Minute
Gets the minute component of the time represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Month
Gets the month component of the date represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
int
Nanosecond
Gets the nanosecond component of the time represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
TimeSpan
Offset
Gets the time's offset from Coordinated Universal Time (UTC).
public
int
Second
Gets the second component of the clock time represented by the current <see cref="T:System.DateTimeOffset" /> object.
public
long
Ticks
Gets the number of ticks that represents the date and time of the current <see cref="T:System.DateTimeOffset" /> object in clock time.
public
TimeSpan
TimeOfDay
Gets the time of day for the current <see cref="T:System.DateTimeOffset" /> object.
public
int
TotalOffsetMinutes
Gets the time's offset from Coordinated Universal Time (UTC) in minutes.
public
DateTime
UtcDateTime
Gets a <see cref="T:System.DateTime" /> value that represents the Coordinated Universal Time (UTC) date and time of the current <see cref="T:System.DateTimeOffset" /> object.
public
long
UtcTicks
Gets the number of ticks that represents the date and time of the current <see cref="T:System.DateTimeOffset" /> object in Coordinated Universal Time (UTC).
public
int
Year
Gets the year component of the date represented by the current <see cref="T:System.DateTimeOffset" /> object.
Methods
public
DateTimeOffset
Add​(TimeSpan timeSpan)
timeSpan
A <see cref="T:System.TimeSpan" /> object that represents a positive or a negative time interval.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the time interval represented by <paramref name="timeSpan" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified time interval to the value of this instance.
public
DateTimeOffset
AddDays​(double days)
days
A number of whole and fractional days. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of days represented by <paramref name="days" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of whole and fractional days to the value of this instance.
public
DateTimeOffset
AddHours​(double hours)
hours
A number of whole and fractional hours. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of hours represented by <paramref name="hours" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of whole and fractional hours to the value of this instance.
public
DateTimeOffset
AddMicroseconds​(double microseconds)
microseconds
A number of whole and fractional microseconds. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of whole microseconds represented by <paramref name="microseconds" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of microseconds to the value of this instance.
public
DateTimeOffset
AddMilliseconds​(double milliseconds)
milliseconds
A number of whole and fractional milliseconds. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of whole milliseconds represented by <paramref name="milliseconds" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of milliseconds to the value of this instance.
public
DateTimeOffset
AddMinutes​(double minutes)
minutes
A number of whole and fractional minutes. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of minutes represented by <paramref name="minutes" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of whole and fractional minutes to the value of this instance.
public
DateTimeOffset
AddMonths​(int months)
months
A number of whole months. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of months represented by <paramref name="months" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of months to the value of this instance.
public
DateTimeOffset
AddSeconds​(double seconds)
seconds
A number of whole and fractional seconds. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of seconds represented by <paramref name="seconds" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of whole and fractional seconds to the value of this instance.
public
DateTimeOffset
AddTicks​(long ticks)
ticks
A number of 100-nanosecond ticks. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of ticks represented by <paramref name="ticks" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of ticks to the value of this instance.
public
DateTimeOffset
AddYears​(int years)
years
A number of years. The number can be negative or positive.
Returns An object whose value is the sum of the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object and the number of years represented by <paramref name="years" /> .
Returns a new <see cref="T:System.DateTimeOffset" /> object that adds a specified number of years to the value of this instance.
public
int
CompareTo​(DateTimeOffset other)
other
An object to compare with the current <see cref="T:System.DateTimeOffset" /> object.
Returns A signed integer that indicates the relationship between the current <see cref="T:System.DateTimeOffset" /> object and <paramref name="other" /> , as the following table shows.
<list type="table">
<listheader>
<term> Return Value</term>
<description> Description</description>
</listheader>
<item>
<term> Less than zero</term>
<description> The current <see cref="T:System.DateTimeOffset" /> object is earlier than <paramref name="other" />.</description>
</item>
<item>
<term> Zero</term>
<description> The current <see cref="T:System.DateTimeOffset" /> object is the same as <paramref name="other" />.</description>
</item>
<item>
<term> Greater than zero.</term>
<description> The current <see cref="T:System.DateTimeOffset" /> object is later than <paramref name="other" />.</description>
</item>
</list>
Compares the current <see cref="T:System.DateTimeOffset" /> object to a specified <see cref="T:System.DateTimeOffset" /> object and indicates whether the current object is earlier than, the same as, or later than the second <see cref="T:System.DateTimeOffset" /> object.
public
bool
Equals​(DateTimeOffset other)
other
An object to compare to the current <see cref="T:System.DateTimeOffset" /> object.
Returns <see langword="true" /> if both <see cref="T:System.DateTimeOffset" /> objects have the same <see cref="P:System.DateTimeOffset.UtcDateTime" /> value; otherwise, <see langword="false" /> .
Determines whether the current <see cref="T:System.DateTimeOffset" /> object represents the same point in time as a specified <see cref="T:System.DateTimeOffset" /> object.
public
bool
Equals​(object obj)
obj
The object to compare to the current <see cref="T:System.DateTimeOffset" /> object.
Returns <see langword="true" /> if the <paramref name="obj" /> parameter is a <see cref="T:System.DateTimeOffset" /> object and represents the same point in time as the current <see cref="T:System.DateTimeOffset" /> object; otherwise, <see langword="false" /> .
Determines whether a <see cref="T:System.DateTimeOffset" /> object represents the same point in time as a specified object.
public
bool
EqualsExact​(DateTimeOffset other)
other
The object to compare to the current <see cref="T:System.DateTimeOffset" /> object.
Returns <see langword="true" /> if the current <see cref="T:System.DateTimeOffset" /> object and <paramref name="other" /> have the same date and time value and the same <see cref="P:System.DateTimeOffset.Offset" /> value; otherwise, <see langword="false" /> .
Determines whether the current <see cref="T:System.DateTimeOffset" /> object represents the same time and has the same offset as a specified <see cref="T:System.DateTimeOffset" /> object.
public
int
GetHashCode​() Returns A 32-bit signed integer hash code.
Returns the hash code for the current <see cref="T:System.DateTimeOffset" /> object.
public
TimeSpan
Subtract​(DateTimeOffset value)
value
An object that represents the value to subtract.
Returns An object that specifies the interval between the two <see cref="T:System.DateTimeOffset" /> objects.
Subtracts a <see cref="T:System.DateTimeOffset" /> value that represents a specific date and time from the current <see cref="T:System.DateTimeOffset" /> object.
public
DateTimeOffset
Subtract​(TimeSpan value)
value
The time interval to subtract.
Returns An object that is equal to the date and time represented by the current <see cref="T:System.DateTimeOffset" /> object, minus the time interval represented by <paramref name="value" /> .
Subtracts a specified time interval from the current <see cref="T:System.DateTimeOffset" /> object.
public
long
ToFileTime​() Returns The value of the current <see cref="T:System.DateTimeOffset" /> object, expressed as a Windows file time.
Converts the value of the current <see cref="T:System.DateTimeOffset" /> object to a Windows file time.
public
DateTimeOffset
ToLocalTime​() Returns An object that represents the date and time of the current <see cref="T:System.DateTimeOffset" /> object converted to local time.
Converts the current <see cref="T:System.DateTimeOffset" /> object to a <see cref="T:System.DateTimeOffset" /> object that represents the local time.
public
DateTimeOffset
ToOffset​(TimeSpan offset)
offset
The offset to convert the <see cref="T:System.DateTimeOffset" /> value to.
Returns An object that is equal to the original <see cref="T:System.DateTimeOffset" /> object (that is, their <see cref="M:System.DateTimeOffset.ToUniversalTime" /> methods return identical points in time) but whose <see cref="P:System.DateTimeOffset.Offset" /> property is set to <paramref name="offset" /> .
Converts the value of the current <see cref="T:System.DateTimeOffset" /> object to the date and time specified by an offset value.
public
string
ToString​() Returns A string representation of a <see cref="T:System.DateTimeOffset" /> object that includes the offset appended at the end of the string.
Converts the value of the current <see cref="T:System.DateTimeOffset" /> object to its equivalent string representation.
public
string
ToString​(IFormatProvider formatProvider)
formatProvider
An object that supplies culture-specific formatting information.
Returns A string representation of the value of the current <see cref="T:System.DateTimeOffset" /> object, as specified by <paramref name="formatProvider" /> .
Converts the value of the current <see cref="T:System.DateTimeOffset" /> object to its equivalent string representation using the specified culture-specific formatting information.
public
string
ToString​(string format)
format
A format string.
Returns A string representation of the value of the current <see cref="T:System.DateTimeOffset" /> object, as specified by <paramref name="format" /> .
Converts the value of the current <see cref="T:System.DateTimeOffset" /> object to its equivalent string representation using the specified format.
public
string
ToString​(string format,
IFormatProvider formatProvider)
format
A format string.
formatProvider
An object that supplies culture-specific formatting information.
Returns A string representation of the value of the current <see cref="T:System.DateTimeOffset" /> object, as specified by <paramref name="format" /> and <paramref name="formatProvider" /> .
Converts the value of the current <see cref="T:System.DateTimeOffset" /> object to its equivalent string representation using the specified format and culture-specific format information.
public
DateTimeOffset
ToUniversalTime​() Returns An object that represents the date and time of the current <see cref="T:System.DateTimeOffset" /> object converted to Coordinated Universal Time (UTC).
Converts the current <see cref="T:System.DateTimeOffset" /> object to a <see cref="T:System.DateTimeOffset" /> value that represents the Coordinated Universal Time (UTC).
public
long
ToUnixTimeMilliseconds​() Returns The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.
Returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.
public
long
ToUnixTimeSeconds​() Returns The number of seconds that have elapsed since 1970-01-01T00:00:00Z.
Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z.
public
bool
TryFormat​(Span`1 utf8Destination,
Int32& bytesWritten,
ReadOnlySpan`1 format = null,
IFormatProvider formatProvider = null)
public
bool
TryFormat​(Span`1 destination,
Int32& charsWritten,
ReadOnlySpan`1 format = null,
IFormatProvider formatProvider = null)
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .