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.​DateTime
Assembly: System.Runtime
Implemented Interfaces
- IComparable
- IComparable`1
- IConvertible
- IEquatable`1
- ISpanFormattable (Inherits: IFormattable)
- ISpanParsable`1 (Inherits: IParsable<​DateTime>)
- IUtf8SpanFormattable
- ISerializable
Represents an instant in time, typically expressed as a date and time of day.
Fields and Constants
public static readonly
DateTime
MaxValue
Represents the largest possible value of <see cref="T:System.DateTime" /> . This field is read-only.
public static readonly
DateTime
MinValue
Represents the smallest possible value of <see cref="T:System.DateTime" /> . This field is read-only.
public static readonly
DateTime
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.DateTime.UnixEpoch" /> defines the point in time when Unix time is equal to 0.
Properties
public
DateTime
Date
Gets the date component of this instance.
public
int
Day
Gets the day of the month represented by this instance.
public
DayOfWeek
DayOfWeek
Gets the day of the week represented by this instance.
public
int
DayOfYear
Gets the day of the year represented by this instance.
public
int
Hour
Gets the hour component of the date represented by this instance.
public
DateTimeKind
Kind
Gets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.
public
int
Microsecond
The microseconds component, expressed as a value between 0 and 999.
public
int
Millisecond
Gets the milliseconds component of the date represented by this instance.
public
int
Minute
Gets the minute component of the date represented by this instance.
public
int
Month
Gets the month component of the date represented by this instance.
public
int
Nanosecond
The nanoseconds component, expressed as a value between 0 and 900 (in increments of 100 nanoseconds).
public static
DateTime
Now
Gets a <see cref="T:System.DateTime" /> object that is set to the current date and time on this computer, expressed as the local time.
public
int
Second
Gets the seconds component of the date represented by this instance.
public
long
Ticks
Gets the number of ticks that represent the date and time of this instance.
public
TimeSpan
TimeOfDay
Gets the time of day for this instance.
public static
DateTime
Today
Gets the current date.
public static
DateTime
UtcNow
Gets a <see cref="T:System.DateTime" /> object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
public
int
Year
Gets the year component of the date represented by this instance.
Methods
public
DateTime
Add​(TimeSpan value)
Returns a new <see cref="T:System.DateTime" /> that adds the value of the specified <see cref="T:System.TimeSpan" /> to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the time interval represented by <paramref name="value" /> .
value
A positive or negative time interval.
public
DateTime
AddDays​(double value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of days to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of days represented by <paramref name="value" /> .
value
A number of whole and fractional days. The <paramref name="value" /> parameter can be negative or positive.
public
DateTime
AddHours​(double value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of hours to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of hours represented by <paramref name="value" /> .
value
A number of whole and fractional hours. The <paramref name="value" /> parameter can be negative or positive.
public
DateTime
AddMicroseconds​(double value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of microseconds to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of microseconds represented by <paramref name="value" /> .
value
A number of whole and fractional microseconds.
The <paramref name="value" /> parameter can be negative or positive.
Note that this value is rounded to the nearest integer.
public
DateTime
AddMilliseconds​(double value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of milliseconds to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of milliseconds represented by <paramref name="value" /> .
value
A number of whole and fractional milliseconds. The <paramref name="value" /> parameter can be negative or positive. Note that this value is rounded to the nearest integer.
public
DateTime
AddMinutes​(double value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of minutes to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of minutes represented by <paramref name="value" /> .
value
A number of whole and fractional minutes. The <paramref name="value" /> parameter can be negative or positive.
public
DateTime
AddMonths​(int months)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of months to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and <paramref name="months" /> .
months
A number of months. The <paramref name="months" /> parameter can be negative or positive.
public
DateTime
AddSeconds​(double value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of seconds to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of seconds represented by <paramref name="value" /> .
value
A number of whole and fractional seconds. The <paramref name="value" /> parameter can be negative or positive.
public
DateTime
AddTicks​(long value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of ticks to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the time represented by <paramref name="value" /> .
value
A number of 100-nanosecond ticks. The <paramref name="value" /> parameter can be positive or negative.
public
DateTime
AddYears​(int value)
Returns a new <see cref="T:System.DateTime" /> that adds the specified number of years to the value of this instance.
Returns An object whose value is the sum of the date and time represented by this instance and the number of years represented by <paramref name="value" /> .
value
A number of years. The <paramref name="value" /> parameter can be negative or positive.
public static
int
Compare​(DateTime t1,
DateTime t2)
Compares two instances of <see cref="T:System.DateTime" /> and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.
Returns A signed number indicating the relative values of <paramref name="t1" /> and <paramref name="t2" /> .
<list type="table">
<listheader>
<term> Value Type</term>
<description> Condition</description>
</listheader>
<item>
<term> Less than zero</term>
<description>
<paramref name="t1" /> is earlier than <paramref name="t2" />.</description>
</item>
<item>
<term> Zero</term>
<description>
<paramref name="t1" /> is the same as <paramref name="t2" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description>
<paramref name="t1" /> is later than <paramref name="t2" />.</description>
</item>
</list>
t1
The first object to compare.
t2
The second object to compare.
public
int
CompareTo​(DateTime value)
Compares the value of this instance to a specified <see cref="T:System.DateTime" /> value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified <see cref="T:System.DateTime" /> value.
Returns A signed number indicating the relative values of this instance and the <paramref name="value" /> parameter.
<list type="table">
<listheader>
<term> Value</term>
<description> Description</description>
</listheader>
<item>
<term> Less than zero</term>
<description> This instance is earlier than <paramref name="value" />.</description>
</item>
<item>
<term> Zero</term>
<description> This instance is the same as <paramref name="value" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> This instance is later than <paramref name="value" />.</description>
</item>
</list>
value
The object to compare to the current instance.
public
int
CompareTo​(object value)
Compares the value of this instance to a specified object that contains a specified <see cref="T:System.DateTime" /> value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified <see cref="T:System.DateTime" /> value.
Returns A signed number indicating the relative values of this instance and <paramref name="value" /> .
<list type="table">
<listheader>
<term> Value</term>
<description> Description</description>
</listheader>
<item>
<term> Less than zero</term>
<description> This instance is earlier than <paramref name="value" />.</description>
</item>
<item>
<term> Zero</term>
<description> This instance is the same as <paramref name="value" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> This instance is later than <paramref name="value" />, or <paramref name="value" /> is <see langword="null" />.</description>
</item>
</list>
value
A boxed object to compare, or <see langword="null" /> .
public static
int
DaysInMonth​(int year,
int month)
Returns the number of days in the specified month and year.
Returns The number of days in <paramref name="month" /> for the specified <paramref name="year" /> .
For example, if <paramref name="month" /> equals 2 for February, the return value is 28 or 29 depending upon whether <paramref name="year" /> is a leap year.
year
The year.
month
The month (a number ranging from 1 to 12).
public
bool
Equals​(DateTime value)
Returns a value indicating whether the value of this instance is equal to the value of the specified <see cref="T:System.DateTime" /> instance.
Returns <see langword="true" /> if the <paramref name="value" /> parameter equals the value of this instance; otherwise, <see langword="false" /> .
value
The object to compare to this instance.
public static
bool
Equals​(DateTime t1,
DateTime t2)
Returns a value indicating whether two <see cref="T:System.DateTime" /> instances have the same date and time value.
Returns <see langword="true" /> if the two values are equal; otherwise, <see langword="false" /> .
t1
The first object to compare.
t2
The second object to compare.
public
bool
Equals​(object value)
Returns a value indicating whether this instance is equal to a specified object.
Returns <see langword="true" /> if <paramref name="value" /> is an instance of <see cref="T:System.DateTime" /> and equals the value of this instance; otherwise, <see langword="false" /> .
value
The object to compare to this instance.
public static
DateTime
FromBinary​(long dateData)
Deserializes a 64-bit binary value and recreates an original serialized <see cref="T:System.DateTime" /> object.
Returns An object that is equivalent to the <see cref="T:System.DateTime" /> object that was serialized by the <see cref="M:System.DateTime.ToBinary" /> method.
dateData
A 64-bit signed integer that encodes the <see cref="P:System.DateTime.Kind" /> property in a 2-bit field and the <see cref="P:System.DateTime.Ticks" /> property in a 62-bit field.
public static
DateTime
FromFileTime​(long fileTime)
Converts the specified Windows file time to an equivalent local time.
Returns An object that represents the local time equivalent of the date and time represented by the <paramref name="fileTime" /> parameter.
fileTime
A Windows file time expressed in ticks.
public static
DateTime
FromFileTimeUtc​(long fileTime)
Converts the specified Windows file time to an equivalent UTC time.
Returns An object that represents the UTC time equivalent of the date and time represented by the <paramref name="fileTime" /> parameter.
fileTime
A Windows file time expressed in ticks.
public static
DateTime
FromOADate​(double d)
Returns a <see cref="T:System.DateTime" /> equivalent to the specified OLE Automation Date.
Returns An object that represents the same date and time as <paramref name="d" /> .
d
An OLE Automation Date value.
public
string[]
GetDateTimeFormats​()
Converts the value of this instance to all the string representations supported by the standard date and time format specifiers.
Returns A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
public
string[]
GetDateTimeFormats​(char format)
Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier.
Returns A string array where each element is the representation of the value of this instance formatted with the <paramref name="format" /> standard date and time format specifier.
format
A standard date and time format string.
public
string[]
GetDateTimeFormats​(char format,
IFormatProvider? provider)
Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier and culture-specific formatting information.
Returns A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
format
A date and time format string.
provider
An object that supplies culture-specific formatting information about this instance.
public
string[]
GetDateTimeFormats​(IFormatProvider? provider)
Converts the value of this instance to all the string representations supported by the standard date and time format specifiers and the specified culture-specific formatting information.
Returns A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
provider
An object that supplies culture-specific formatting information about this instance.
public
int
GetHashCode​()
Returns the hash code for this instance.
Returns A 32-bit signed integer hash code.
public
TypeCode
GetTypeCode​()
Returns the <see cref="T:System.TypeCode" /> for value type <see cref="T:System.DateTime" /> .
Returns The enumerated constant, <see cref="F:System.TypeCode.DateTime" /> .
public
bool
IsDaylightSavingTime​()
Indicates whether this instance of <see cref="T:System.DateTime" /> is within the daylight saving time range for the current time zone.
Returns <see langword="true" /> if the value of the <see cref="P:System.DateTime.Kind" /> property is <see cref="F:System.DateTimeKind.Local" /> or <see cref="F:System.DateTimeKind.Unspecified" /> and the value of this instance of <see cref="T:System.DateTime" /> is within the daylight saving time range for the local time zone; <see langword="false" /> if <see cref="P:System.DateTime.Kind" /> is <see cref="F:System.DateTimeKind.Utc" /> .
public static
bool
IsLeapYear​(int year)
Returns an indication whether the specified year is a leap year.
Returns <see langword="true" /> if <paramref name="year" /> is a leap year; otherwise, <see langword="false" /> .
year
A 4-digit year.
public static
DateTime
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider)
Parses a span of characters into a value.
Returns The result of parsing <paramref name="s" /> .
s
The span of characters to parse.
provider
An object that provides culture-specific formatting information about <paramref name="s" /> .
public static
DateTime
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider = null,
DateTimeStyles styles = 0)
Converts a memory span that contains string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent by using culture-specific format information and a formatting style.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="provider" /> and <paramref name="styles" /> .
s
The memory span that contains the string to parse. See The string to parse for more information.
provider
An object that supplies culture-specific format information about <paramref name="s" /> . See Parsing and cultural conventions
styles
A bitwise combination of the enumeration values that indicates the style elements that can be present in <paramref name="s" /> for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateTime
Parse​(string s)
Converts the string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent by using the conventions of the current culture.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> .
s
A string that contains a date and time to convert. See The string to parse for more information.
public static
DateTime
Parse​(string s,
IFormatProvider? provider)
Converts the string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent by using culture-specific format information.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> as specified by <paramref name="provider" /> .
s
A string that contains a date and time to convert. See The string to parse for more information.
provider
An object that supplies culture-specific format information about <paramref name="s" /> . See Parsing and cultural conventions
public static
DateTime
Parse​(string s,
IFormatProvider? provider,
DateTimeStyles styles)
Converts the string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent by using culture-specific format information and a formatting style.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="provider" /> and <paramref name="styles" /> .
s
A string that contains a date and time to convert. See The string to parse for more information.
provider
An object that supplies culture-specific formatting information about <paramref name="s" /> . See Parsing and cultural conventions
styles
A bitwise combination of the enumeration values that indicates the style elements that can be present in <paramref name="s" /> for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateTime
ParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified span representation of a date and time to its <see cref="T:System.DateTime" /> equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="format" /> , <paramref name="provider" /> , and <paramref name="style" /> .
s
A span containing the characters that represent a date and time to convert.
format
A span containing the characters that represent a format specifier that defines the required format of <paramref name="s" /> .
provider
An object that supplies culture-specific formatting information about <paramref name="s" /> .
style
A bitwise combination of the enumeration values that provides additional information about <paramref name="s" /> , about style elements that may be present in <paramref name="s" /> , or about the conversion from <paramref name="s" /> to a <see cref="T:System.DateTime" /> value. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateTime
ParseExact​(ReadOnlySpan<​char> s,
string[] formats,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified span representation of a date and time to its <see cref="T:System.DateTime" /> equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="formats" /> , <paramref name="provider" /> , and <paramref name="style" /> .
s
A span containing the characters that represent a date and time to convert.
formats
An array of allowable formats of <paramref name="s" /> .
provider
An object that supplies culture-specific format information about <paramref name="s" /> .
style
A bitwise combination of enumeration values that indicates the permitted format of <paramref name="s" /> . A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateTime
ParseExact​(string s,
string format,
IFormatProvider? provider)
Converts the specified string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="format" /> and <paramref name="provider" /> .
s
A string that contains a date and time to convert.
format
A format specifier that defines the required format of <paramref name="s" /> . For more information, see the Remarks section.
provider
An object that supplies culture-specific format information about <paramref name="s" /> .
public static
DateTime
ParseExact​(string s,
string format,
IFormatProvider? provider,
DateTimeStyles style)
Converts the specified string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="format" /> , <paramref name="provider" /> , and <paramref name="style" /> .
s
A string containing a date and time to convert.
format
A format specifier that defines the required format of <paramref name="s" /> . For more information, see the Remarks section.
provider
An object that supplies culture-specific formatting information about <paramref name="s" /> .
style
A bitwise combination of the enumeration values that provides additional information about <paramref name="s" /> , about style elements that may be present in <paramref name="s" /> , or about the conversion from <paramref name="s" /> to a <see cref="T:System.DateTime" /> value. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateTime
ParseExact​(string s,
string[] formats,
IFormatProvider? provider,
DateTimeStyles style)
Converts the specified string representation of a date and time to its <see cref="T:System.DateTime" /> equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown.
Returns An object that is equivalent to the date and time contained in <paramref name="s" /> , as specified by <paramref name="formats" /> , <paramref name="provider" /> , and <paramref name="style" /> .
s
A string that contains a date and time to convert.
formats
An array of allowable formats of <paramref name="s" /> . For more information, see the Remarks section.
provider
An object that supplies culture-specific format information about <paramref name="s" /> .
style
A bitwise combination of enumeration values that indicates the permitted format of <paramref name="s" /> . A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateTime
SpecifyKind​(DateTime value,
DateTimeKind kind)
Creates a new <see cref="T:System.DateTime" /> object that has the same number of ticks as the specified <see cref="T:System.DateTime" /> , but is designated as either local time, Coordinated Universal Time (UTC), or neither, as indicated by the specified <see cref="T:System.DateTimeKind" /> value.
Returns A new object that has the same number of ticks as the object represented by the <paramref name="value" /> parameter and the <see cref="T:System.DateTimeKind" /> value specified by the <paramref name="kind" /> parameter.
value
A date and time.
kind
One of the enumeration values that indicates whether the new object represents local time, UTC, or neither.
public
TimeSpan
Subtract​(DateTime value)
Returns a new <see cref="T:System.TimeSpan" /> that subtracts the specified date and time from the value of this instance.
Returns A time interval that is equal to the date and time represented by this instance minus the date and time represented by <paramref name="value" /> .
value
The date and time value to subtract.
public
DateTime
Subtract​(TimeSpan value)
Returns a new <see cref="T:System.DateTime" /> that subtracts the specified duration from the value of this instance.
Returns An object that is equal to the date and time represented by this instance minus the time interval represented by <paramref name="value" /> .
value
The time interval to subtract.
public
long
ToBinary​()
Serializes the current <see cref="T:System.DateTime" /> object to a 64-bit binary value that subsequently can be used to recreate the <see cref="T:System.DateTime" /> object.
Returns A 64-bit signed integer that encodes the <see cref="P:System.DateTime.Kind" /> and <see cref="P:System.DateTime.Ticks" /> properties.
public
long
ToFileTime​()
Converts the value of the current <see cref="T:System.DateTime" /> object to a Windows file time.
Returns The value of the current <see cref="T:System.DateTime" /> object expressed as a Windows file time.
public
long
ToFileTimeUtc​()
Converts the value of the current <see cref="T:System.DateTime" /> object to a Windows file time.
Returns The value of the current <see cref="T:System.DateTime" /> object expressed as a Windows file time.
public
DateTime
ToLocalTime​()
Converts the value of the current <see cref="T:System.DateTime" /> object to local time.
Returns An object whose <see cref="P:System.DateTime.Kind" /> property is <see cref="F:System.DateTimeKind.Local" /> , and whose value is the local time equivalent to the value of the current <see cref="T:System.DateTime" /> object, or <see cref="F:System.DateTime.MaxValue">DateTime.MaxValue</see> if the converted value is too large to be represented by a <see cref="T:System.DateTime" /> object, or <see cref="F:System.DateTime.MinValue">DateTime.MinValue</see> if the converted value is too small to be represented as a <see cref="T:System.DateTime" /> object.
public
string
ToLongDateString​()
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent long date string representation.
Returns A string that contains the long date string representation of the current <see cref="T:System.DateTime" /> object.
public
string
ToLongTimeString​()
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent long time string representation.
Returns A string that contains the long time string representation of the current <see cref="T:System.DateTime" /> object.
public
double
ToOADate​()
Converts the value of this instance to the equivalent OLE Automation date.
Returns A double-precision floating-point number that contains an OLE Automation date equivalent to the value of this instance.
public
string
ToShortDateString​()
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent short date string representation.
Returns A string that contains the short date string representation of the current <see cref="T:System.DateTime" /> object.
public
string
ToShortTimeString​()
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent short time string representation.
Returns A string that contains the short time string representation of the current <see cref="T:System.DateTime" /> object.
public
string
ToString​()
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent string representation using the formatting conventions of the current culture.
Returns A string representation of the value of the current <see cref="T:System.DateTime" /> object.
public
string
ToString​(IFormatProvider? provider)
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent string representation using the specified culture-specific format information.
Returns A string representation of value of the current <see cref="T:System.DateTime" /> object as specified by <paramref name="provider" /> .
provider
An object that supplies culture-specific formatting information.
public
string
ToString​(string format)
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent string representation using the specified format and the formatting conventions of the current culture.
Returns A string representation of value of the current <see cref="T:System.DateTime" /> object as specified by <paramref name="format" /> .
format
A standard or custom date and time format string.
public
string
ToString​(string format,
IFormatProvider provider)
Converts the value of the current <see cref="T:System.DateTime" /> object to its equivalent string representation using the specified format and culture-specific format information.
Returns A string representation of value of the current <see cref="T:System.DateTime" /> object as specified by <paramref name="format" /> and <paramref name="provider" /> .
format
A standard or custom date and time format string.
provider
An object that supplies culture-specific formatting information.
public
DateTime
ToUniversalTime​()
Converts the value of the current <see cref="T:System.DateTime" /> object to Coordinated Universal Time (UTC).
Returns An object whose <see cref="P:System.DateTime.Kind" /> property is <see cref="F:System.DateTimeKind.Utc" /> , and whose value is the UTC equivalent to the value of the current <see cref="T:System.DateTime" /> object, or <see cref="F:System.DateTime.MaxValue">DateTime.MaxValue</see> if the converted value is too large to be represented by a <see cref="T:System.DateTime" /> object, or <see cref="F:System.DateTime.MinValue">DateTime.MinValue</see> if the converted value is too small to be represented by a <see cref="T:System.DateTime" /> object.
public
bool
TryFormat​(Span<​byte> utf8Destination,
Int32& bytesWritten,
ReadOnlySpan<​char> format = null,
IFormatProvider? provider = null)
public
bool
TryFormat​(Span<​char> destination,
Int32& charsWritten,
ReadOnlySpan<​char> format = null,
IFormatProvider? provider = null)
public static
bool
TryParse​(ReadOnlySpan<​char> s,
IFormatProvider? provider,
DateTime& result)
public static
bool
TryParse​(ReadOnlySpan<​char> s,
IFormatProvider? provider,
DateTimeStyles styles,
DateTime& result)
public static
bool
TryParse​(string s,
IFormatProvider provider,
DateTimeStyles styles,
DateTime& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
IFormatProvider? provider,
DateTimeStyles style,
DateTime& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
string[] formats,
IFormatProvider provider,
DateTimeStyles style,
DateTime& result)
public static
bool
TryParseExact​(string s,
string format,
IFormatProvider provider,
DateTimeStyles style,
DateTime& result)
public static
bool
TryParseExact​(string s,
string[] formats,
IFormatProvider provider,
DateTimeStyles style,
DateTime& result)
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
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .