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
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
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)
value
The number of days to add. To subtract days, specify a negative number.
Returns An instance whose value is the sum of the date represented by this instance and the number of days represented by value.
Adds the specified number of days to the value of this instance.
public
DateOnly
AddMonths​(int value)
value
A number of months. The months parameter can be negative or positive.
Returns An object whose value is the sum of the date represented by this instance and months.
Adds the specified number of months to the value of this instance.
public
DateOnly
AddYears​(int value)
value
A number of years. The value parameter can be negative or positive.
Returns An object whose value is the sum of the date represented by this instance and the number of years represented by value.
Adds the specified number of years to the value of this instance.
public
int
CompareTo​(DateOnly value)
value
The object to compare to the current instance.
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.
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.
public
int
CompareTo​(object value)
value
A boxed object to compare, or <see langword="null" /> .
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.
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.
public
bool
Equals​(DateOnly value)
value
The object to compare to this instance.
Returns <see langword="true" /> if the value parameter equals the value of this instance; otherwise, <see langword="false" /> .
Returns a value indicating whether the value of this instance is equal to the value of the specified <see cref="T:System.DateOnly" /> instance.
public
bool
Equals​(object value)
value
The object to compare to this instance.
Returns <see langword="true" /> if value is an instance of DateOnly and equals the value of this instance; otherwise, <see langword="false" /> .
Returns a value indicating whether this instance is equal to a specified object.
public
int
GetHashCode​() Returns A 32-bit signed integer hash code.
Returns the hash code for this instance.
public
DateTime
ToDateTime​(TimeOnly time)
time
The time of the day.
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.
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.
public
DateTime
ToDateTime​(TimeOnly time,
DateTimeKind kind)
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.
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.
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.
public
string
ToLongDateString​() Returns A string that contains the long date string representation of the current <see cref="T:System.DateOnly" /> object.
Converts the value of the current <see cref="T:System.DateOnly" /> object to its equivalent long date string representation.
public
string
ToShortDateString​() Returns A string that contains the short date string representation of the current <see cref="T:System.DateOnly" /> object.
Converts the value of the current <see cref="T:System.DateOnly" /> object to its equivalent short date string representation.
public
string
ToString​() Returns A string that contains the short date string representation of the current <see cref="T:System.DateOnly" /> object.
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.
public
string
ToString​(IFormatProvider provider)
provider
An object that supplies culture-specific formatting information.
Returns A string representation of value of the current <see cref="T:System.DateOnly" /> object as specified by 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.
public
string
ToString​(string format)
format
A standard or custom date format string.
Returns A string representation of value of the current <see cref="T:System.DateOnly" /> object as specified by 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.
public
string
ToString​(string format,
IFormatProvider provider)
format
A standard or custom date format string.
provider
An object that supplies culture-specific formatting information.
Returns A string representation of value of the current <see cref="T:System.DateOnly" /> object as specified by format and 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.
public
bool
TryFormat​(Span`1 utf8Destination,
Int32& bytesWritten,
ReadOnlySpan`1 format = null,
IFormatProvider provider = null)
public
bool
TryFormat​(Span`1 destination,
Int32& charsWritten,
ReadOnlySpan`1 format = null,
IFormatProvider provider = 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" /> .