Struct DateFormat
Represents a date format (the year, the month of the year, and the day of the month)
public readonly struct DateFormat : IEquatable<DateFormat>, ISpanFormattable, IFormattable, IEqualityOperators<DateFormat, DateFormat, bool>
- Implements
- Inherited Members
Properties
DayMonthYear
Gets the "Day / Month / Year" date format
public static DateFormat DayMonthYear { get; }
Property Value
- DateFormat
The "Day / Month / Year" date format
MonthDayYear
Gets the "Month / Day / Year" date format
public static DateFormat MonthDayYear { get; }
Property Value
- DateFormat
The "Month / Day / Year" date format
YearMonthDay
Gets the "Year / Month / Day" date format
public static DateFormat YearMonthDay { get; }
Property Value
- DateFormat
The "Year / Month / Day" date format
Methods
Equals(DateFormat)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(DateFormat other)
Parameters
otherDateFormatAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToString(IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(IFormatProvider? formatProvider)
Parameters
formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
ToString(string?)
Formats the value of the current instance using the specified format.
public string ToString(string? format)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.
Returns
- string
The value of the current instance in the specified format.
ToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
Parameters
destinationSpan<char>The span in which to write this instance's value formatted as a span of characters.
charsWrittenintWhen this method returns, contains the number of characters that were written in
destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
destination.
Returns
TryGetLocalePreference(out DateFormat)
Tries to get the current preferred date format for the system locale
public static bool TryGetLocalePreference(out DateFormat dateFormat)
Parameters
dateFormatDateFormatThe current preferred date format
Returns
- bool
true, if the current preferred date format could be successfully retrieved; otherwise,false(check TryGet(out string?) for more information)
Remarks
This might be a "slow" call that has to query the operating system. It's best to ask for this once and save the results. However, the preferred formats can change, usually because the user has changed a system preference outside of your program.
To get the current preferred date format as well as the current preferred time format simultaneously, use TryGetLocalePreferences(out DateFormat, out TimeFormat) instead.
Operators
operator ==(DateFormat, DateFormat)
Compares two values to determine equality.
public static bool operator ==(DateFormat left, DateFormat right)
Parameters
leftDateFormatThe value to compare with
right.rightDateFormatThe value to compare with
left.
Returns
operator !=(DateFormat, DateFormat)
Compares two values to determine inequality.
public static bool operator !=(DateFormat left, DateFormat right)
Parameters
leftDateFormatThe value to compare with
right.rightDateFormatThe value to compare with
left.