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.​DateOnly
Assembly: System.Runtime
Implemented Interfaces
- IComparable
- IComparable`1
- IEquatable`1
- ISpanFormattable (Inherits: IFormattable)
- ISpanParsable`1 (Inherits: IParsable<​DateOnly>)
- IUtf8SpanFormattable
Represents dates with values ranging from January 1, 0001 Anno Domini (Common Era) through December 31, 9999 A.D. (C.E.) in the Gregorian calendar.
Properties
public
int
Day
Gets the day component of the date represented by this instance.
public
int
DayNumber
Gets the number of days since January 1, 0001 in the Proleptic Gregorian calendar 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 static
DateOnly
MaxValue
Gets the latest possible date that can be created.
public static
DateOnly
MinValue
Gets the earliest possible date that can be created.
public
int
Month
Gets the month component of the date represented by this instance.
public
int
Year
Gets the year component of the date represented by this instance.
Methods
public
DateOnly
AddDays​(int value)
Adds the specified number of days to the value of this instance.
Returns An instance whose value is the sum of the date represented by this instance and the number of days represented by value.
value
The number of days to add. To subtract days, specify a negative number.
public
DateOnly
AddMonths​(int value)
Adds the specified number of months to the value of this instance.
Returns An object whose value is the sum of the date represented by this instance and months.
value
A number of months. The months parameter can be negative or positive.
public
DateOnly
AddYears​(int value)
Adds the specified number of years to the value of this instance.
Returns An object whose value is the sum of the date represented by this instance and the number of years represented by value.
value
A number of years. The value parameter can be negative or positive.
public
int
CompareTo​(DateOnly value)
Compares the value of this instance to a specified <see cref="T:System.DateOnly" /> 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.DateOnly" /> value.
Returns Less than zero if this instance is earlier than value. Greater than zero if this instance is later than value. Zero if this instance is the same as value.
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.DateOnly" /> 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.DateOnly" /> value.
Returns Less than zero if this instance is earlier than value. Greater than zero if this instance is later than value. Zero if this instance is the same as value.
value
A boxed object to compare, or <see langword="null" /> .
public
bool
Equals​(DateOnly value)
Returns a value indicating whether the value of this instance is equal to the value of the specified <see cref="T:System.DateOnly" /> instance.
Returns <see langword="true" /> if the value parameter equals the value of this instance; otherwise, <see langword="false" /> .
value
The object to compare to this instance.
public
bool
Equals​(object value)
Returns a value indicating whether this instance is equal to a specified object.
Returns <see langword="true" /> if value is an instance of DateOnly and equals the value of this instance; otherwise, <see langword="false" /> .
value
The object to compare to this instance.
public static
DateOnly
FromDateTime​(DateTime dateTime)
Returns a <see cref="T:System.DateOnly" /> instance that is set to the date part of the specified <paramref name="dateTime" /> .
Returns The <see cref="T:System.DateOnly" /> instance composed of the date part of the specified input time <paramref name="dateTime" /> instance.
dateTime
The <see cref="T:System.DateTime" /> instance.
public static
DateOnly
FromDayNumber​(int dayNumber)
Creates a new instance of the <see cref="T:System.DateOnly" /> structure to the specified number of days.
Returns A <see cref="T:System.DateOnly" /> structure instance to the specified number of days.
dayNumber
The number of days since January 1, 0001 in the Proleptic Gregorian calendar.
public
int
GetHashCode​()
Returns the hash code for this instance.
Returns A 32-bit signed integer hash code.
public static
DateOnly
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
DateOnly
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider = null,
DateTimeStyles style = 0)
Converts a memory span that contains string representation of a date to its <see cref="T:System.DateOnly" /> equivalent by using culture-specific format information and a formatting style.
Returns An object that is equivalent to the date contained in <paramref name="s" /> , as specified by provider and styles.
s
The memory span that contains the string to parse.
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
DateOnly
Parse​(string s)
Converts a string that contains string representation of a date to its <see cref="T:System.DateOnly" /> equivalent by using the conventions of the current culture.
Returns An object that is equivalent to the date contained in <paramref name="s" /> .
s
The string that contains the string to parse.
public static
DateOnly
Parse​(string s,
IFormatProvider? provider)
Parses a string into a value.
Returns The result of parsing <paramref name="s" /> .
s
The string to parse.
provider
An object that provides culture-specific formatting information about <paramref name="s" /> .
public static
DateOnly
Parse​(string s,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts a string that contains string representation of a date to its <see cref="T:System.DateOnly" /> equivalent by using culture-specific format information and a formatting style.
Returns An object that is equivalent to the date contained in <paramref name="s" /> , as specified by provider and styles.
s
The string that contains the string to parse.
provider
An object that supplies culture-specific format information about <paramref name="s" /> .
style
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. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateOnly
ParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
IFormatProvider? provider = null,
DateTimeStyles style = 0)
Converts the specified span representation of a date to its <see cref="T:System.DateOnly" /> 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 contained in <paramref name="s" /> , as specified by format, provider, and style.
s
A span containing the characters that represent a date 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 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
DateOnly
ParseExact​(ReadOnlySpan<​char> s,
string[] formats)
Converts the specified span representation of a date to its <see cref="T:System.DateOnly" /> equivalent using the specified array of formats.
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 contained in <paramref name="s" /> , as specified by format, provider, and style.
s
A span containing the characters that represent a date to convert.
formats
An array of allowable formats of <paramref name="s" /> .
public static
DateOnly
ParseExact​(ReadOnlySpan<​char> s,
string[] formats,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified span representation of a date to its <see cref="T:System.DateOnly" /> 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 contained in <paramref name="s" /> , as specified by format, provider, and style.
s
A span containing the characters that represent a date to convert.
formats
An array of allowable formats of <paramref name="s" /> .
provider
An object that supplies culture-specific formatting 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
DateOnly
ParseExact​(string s,
string format)
Converts the specified string representation of a date to its <see cref="T:System.DateOnly" /> equivalent using the specified format.
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 contained in <paramref name="s" /> , as specified by format.
s
A string containing the characters that represent a date to convert.
format
A string that represent a format specifier that defines the required format of <paramref name="s" /> .
public static
DateOnly
ParseExact​(string s,
string format,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified string representation of a date to its <see cref="T:System.DateOnly" /> 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 contained in <paramref name="s" /> , as specified by format, provider, and style.
s
A string containing the characters that represent a date to convert.
format
A string 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.DateOnly" /> value. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
DateOnly
ParseExact​(string s,
string[] formats)
Converts the specified span representation of a date to its <see cref="T:System.DateOnly" /> equivalent using the specified array of formats.
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 contained in <paramref name="s" /> , as specified by format, provider, and style.
s
A span containing the characters that represent a date to convert.
formats
An array of allowable formats of <paramref name="s" /> .
public static
DateOnly
ParseExact​(string s,
string[] formats,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified string representation of a date to its <see cref="T:System.DateOnly" /> 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 contained in <paramref name="s" /> , as specified by format, provider, and style.
s
A string containing the characters that represent a date to convert.
formats
An array of allowable formats of <paramref name="s" /> .
provider
An object that supplies culture-specific formatting 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
DateTime
ToDateTime​(TimeOnly time)
Returns a <see cref="T:System.DateTime" /> that is set to the date of this <see cref="T:System.DateOnly" /> instance and the time of specified input time.
Returns The <see cref="T:System.DateTime" /> instance composed of the date of the current <see cref="T:System.DateOnly" /> instance and the time specified by the input time.
time
The time of the day.
public
DateTime
ToDateTime​(TimeOnly time,
DateTimeKind kind)
Returns a <see cref="T:System.DateTime" /> instance with the specified input kind that is set to the date of this <see cref="T:System.DateOnly" /> instance and the time of specified input time.
Returns The <see cref="T:System.DateTime" /> instance composed of the date of the current <see cref="T:System.DateOnly" /> instance and the time specified by the input time.
time
The time of the day.
kind
One of the enumeration values that indicates whether ticks specifies a local time, Coordinated Universal Time (UTC), or neither.
public
string
ToLongDateString​()
Converts the value of the current <see cref="T:System.DateOnly" /> 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.DateOnly" /> object.
public
string
ToShortDateString​()
Converts the value of the current <see cref="T:System.DateOnly" /> 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.DateOnly" /> object.
public
string
ToString​()
Converts the value of the current <see cref="T:System.DateOnly" /> object to its equivalent string representation using the formatting conventions of the current culture.
The <see cref="T:System.DateOnly" /> object will be formatted in short form.
Returns A string that contains the short date string representation of the current <see cref="T:System.DateOnly" /> object.
public
string
ToString​(IFormatProvider? provider)
Converts the value of the current <see cref="T:System.DateOnly" /> 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.DateOnly" /> object as specified by 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.DateOnly" /> 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.DateOnly" /> object as specified by format.
format
A standard or custom date format string.
public
string
ToString​(string format,
IFormatProvider provider)
Converts the value of the current <see cref="T:System.DateOnly" /> 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.DateOnly" /> object as specified by format and provider.
format
A standard or custom date format string.
provider
An object that supplies culture-specific formatting information.
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,
DateOnly& result)
public static
bool
TryParse​(ReadOnlySpan<​char> s,
IFormatProvider? provider,
DateTimeStyles style,
DateOnly& result)
public static
bool
TryParse​(string s,
IFormatProvider provider,
DateTimeStyles style,
DateOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
DateOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
IFormatProvider? provider,
DateTimeStyles style,
DateOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
string[] formats,
DateOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
string[] formats,
IFormatProvider provider,
DateTimeStyles style,
DateOnly& result)
public static
bool
TryParseExact​(string s,
string format,
IFormatProvider provider,
DateTimeStyles style,
DateOnly& result)
public static
bool
TryParseExact​(string s,
string[] formats,
IFormatProvider provider,
DateTimeStyles style,
DateOnly& 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" /> .