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.​TimeOnly
Assembly: System.Runtime
Implemented Interfaces
- IComparable
- IComparable`1
- IEquatable`1
- ISpanFormattable (Inherits: IFormattable)
- ISpanParsable`1 (Inherits: IParsable<​TimeOnly>)
- IUtf8SpanFormattable
Represents a time of day, as would be read from a clock, within the range 00:00:00 to 23:59:59.9999999.
Properties
public
int
Hour
Gets the hour component of the time represented by this instance.
public static
TimeOnly
MaxValue
Gets the largest possible value of <see cref="T:System.TimeOnly" /> .
public
int
Microsecond
Gets the microsecond component of the time represented by this instance.
public
int
Millisecond
Gets the millisecond component of the time represented by this instance.
public
int
Minute
Gets the minute component of the time represented by this instance.
public static
TimeOnly
MinValue
Gets the smallest possible value of <see cref="T:System.TimeOnly" /> .
public
int
Nanosecond
Gets the nanosecond component of the time represented by this instance.
public
int
Second
Gets the seconds component of the time represented by this instance.
public
long
Ticks
Gets the number of ticks that represent the time of this instance.
Methods
public
TimeOnly
Add​(TimeSpan value)
Returns a new <see cref="T:System.TimeOnly" /> that adds the value of the specified time span to the value of this instance.
Returns An object whose value is the sum of the time represented by this instance and the time interval represented by value.
value
A positive or negative time interval.
public
TimeOnly
AddHours​(double value)
Returns a new <see cref="T:System.TimeOnly" /> that adds the specified number of hours to the value of this instance.
Returns An object whose value is the sum of the time represented by this instance and the number of hours represented by value.
value
A number of whole and fractional hours. The value parameter can be negative or positive.
public
TimeOnly
AddMinutes​(double value)
Returns a new <see cref="T:System.TimeOnly" /> that adds the specified number of minutes to the value of this instance.
Returns An object whose value is the sum of the time represented by this instance and the number of minutes represented by value.
value
A number of whole and fractional minutes. The value parameter can be negative or positive.
public
int
CompareTo​(object value)
Compares the value of this instance to a specified object that contains a specified <see cref="T:System.TimeOnly" /> 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.TimeOnly" /> value.
Returns A signed number indicating the relative values of this instance and the value parameter.
Less than zero if this instance is earlier than value.
Zero if this instance is the same as value.
Greater than zero if this instance is later than value.
value
A boxed object to compare, or <see langword="null" /> .
public
int
CompareTo​(TimeOnly value)
Compares the value of this instance to a specified <see cref="T:System.TimeOnly" /> value and indicates whether this instance is earlier than, the same as, or later than the specified <see cref="T:System.TimeOnly" /> value.
Returns A signed number indicating the relative values of this instance and the value parameter.
- Less than zero if this instance is earlier than value.
- Zero if this instance is the same as value.
- Greater than zero if this instance is later than value.
value
The object to compare to the current instance.
public
void
Deconstruct​(Int32& hour,
Int32& minute,
Int32& second,
Int32& millisecond)
public
void
Deconstruct​(Int32& hour,
Int32& minute,
Int32& second,
Int32& millisecond,
Int32& microsecond)
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 <see cref="T:System.TimeOnly" /> and equals the value of this instance; otherwise, <see langword="false" /> .
value
The object to compare to this instance.
public
bool
Equals​(TimeOnly value)
Returns a value indicating whether the value of this instance is equal to the value of the specified <see cref="T:System.TimeOnly" /> 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 static
TimeOnly
FromDateTime​(DateTime dateTime)
Constructs a <see cref="T:System.TimeOnly" /> object from a <see cref="T:System.DateTime" /> representing the time of the day in this <see cref="T:System.DateTime" /> object.
Returns A <see cref="T:System.TimeOnly" /> object representing time of the day specified in the <see cref="T:System.DateTime" /> object.
dateTime
The <see cref="T:System.DateTime" /> object to extract the time of the day from.
public static
TimeOnly
FromTimeSpan​(TimeSpan timeSpan)
Constructs a <see cref="T:System.TimeOnly" /> object from a time span representing the time elapsed since midnight.
Returns A <see cref="T:System.TimeOnly" /> object representing the time elapsed since midnight using the specified time span value.
timeSpan
The time interval measured since midnight. This value has to be positive and not exceeding the time of the day.
public
int
GetHashCode​()
Returns the hash code for this instance.
Returns A 32-bit signed integer hash code.
public
bool
IsBetween​(TimeOnly start,
TimeOnly end)
Determines if a time falls within the range provided.
Supports both "normal" ranges such as 10:00-12:00, and ranges that span midnight such as 23:00-01:00.
Returns <see langword="true" /> , if the time falls within the range, <see langword="false" /> otherwise.
start
The starting time of day, inclusive.
end
The ending time of day, exclusive.
public static
TimeOnly
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider)
Parses a span of characters into a value.
Returns The result of parsing <paramref name="s" /> .
s
A span of characters to parse.
provider
An object that provides culture-specific formatting information about <paramref name="s" /> .
public static
TimeOnly
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider = null,
DateTimeStyles style = 0)
Converts a memory span that contains string representation of a time to its <see cref="T:System.TimeOnly" /> equivalent by using culture-specific format information and a formatting style.
Returns A <see cref="T:System.TimeOnly" /> instance.
s
The memory span that contains the time to parse.
provider
The 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
TimeOnly
Parse​(string s)
Converts the string representation of a time to its <see cref="T:System.TimeOnly" /> equivalent by using the conventions of the current culture.
Returns A <see cref="T:System.TimeOnly" /> instance.
s
The string to parse.
public static
TimeOnly
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
TimeOnly
Parse​(string s,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the string representation of a time to its <see cref="T:System.TimeOnly" /> equivalent by using culture-specific format information and a formatting style.
Returns A <see cref="T:System.TimeOnly" /> instance.
s
The string containing the time to parse.
provider
The 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 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
TimeOnly
ParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
IFormatProvider? provider = null,
DateTimeStyles style = 0)
Converts the specified span representation of a time to its <see cref="T:System.TimeOnly" /> 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 A <see cref="T:System.TimeOnly" /> instance.
s
A span containing the time to convert.
format
The format specifier that defines the required format of <paramref name="s" /> .
provider
The 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
TimeOnly
ParseExact​(ReadOnlySpan<​char> s,
string[] formats)
Converts the specified span to its <see cref="T:System.TimeOnly" /> 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 A <see cref="T:System.TimeOnly" /> instance.
s
A span containing the time to convert.
formats
An array of allowable formats of <paramref name="s" /> .
public static
TimeOnly
ParseExact​(ReadOnlySpan<​char> s,
string[] formats,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified span representation of a time to its <see cref="T:System.TimeOnly" /> 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 A <see cref="T:System.TimeOnly" /> instance.
s
A span containing the time to convert.
formats
An array of allowable formats of <paramref name="s" /> .
provider
The 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
TimeOnly
ParseExact​(string s,
string format)
Converts the specified string representation of a time to its <see cref="T:System.TimeOnly" /> equivalent using the specified format.
The format of the string representation must match the specified format exactly or an exception is thrown.
Returns A <see cref="T:System.TimeOnly" /> instance.
s
A string containing a time to convert.
format
A format specifier that defines the required format of <paramref name="s" /> .
public static
TimeOnly
ParseExact​(string s,
string format,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified string representation of a time to its <see cref="T:System.TimeOnly" /> 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 A <see cref="T:System.TimeOnly" /> instance.
s
A string containing the time to convert.
format
The format specifier that defines the required format of <paramref name="s" /> .
provider
The 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.TimeOnly" /> value. A typical value to specify is <see cref="F:System.Globalization.DateTimeStyles.None" /> .
public static
TimeOnly
ParseExact​(string s,
string[] formats)
Converts the specified span to a <see cref="T:System.TimeOnly" /> 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 A <see cref="T:System.TimeOnly" /> instance.
s
A span containing the time to convert.
formats
An array of allowable formats of <paramref name="s" /> .
public static
TimeOnly
ParseExact​(string s,
string[] formats,
IFormatProvider? provider,
DateTimeStyles style = 0)
Converts the specified string representation of a time to its <see cref="T:System.TimeOnly" /> 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 A <see cref="T:System.TimeOnly" /> instance.
s
A string containing the time to convert.
formats
An array of allowable formats of <paramref name="s" /> .
provider
The 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
string
ToLongTimeString​()
Converts the value of the current <see cref="T:System.TimeOnly" /> instance to its equivalent long date string representation.
Returns The long time string representation of the current instance.
public
string
ToShortTimeString​()
Converts the current <see cref="T:System.TimeOnly" /> instance to its equivalent short time string representation.
Returns The short time string representation of the current instance.
public
string
ToString​()
Converts the current <see cref="T:System.TimeOnly" /> instance to its equivalent short time string representation using the formatting conventions of the current culture.
Returns The short time string representation of the current instance.
public
string
ToString​(IFormatProvider? provider)
Converts the value of the current <see cref="T:System.TimeOnly" /> instance to its equivalent string representation using the specified culture-specific format information.
Returns A string representation of the current instance as specified by the provider.
provider
The culture-specific formatting information.
public
string
ToString​(string format)
Converts the current <see cref="T:System.TimeOnly" /> instance to its equivalent string representation using the specified format and the formatting conventions of the current culture.
Returns A string representation of the current instance with the specified format and the formatting conventions of the current culture.
format
A standard or custom time format string.
public
string
ToString​(string format,
IFormatProvider provider)
Converts the value of the current <see cref="T:System.TimeOnly" /> instance to its equivalent string representation using the specified culture-specific format information.
Returns A string representation of value of the current instance.
format
A standard or custom time format string.
provider
The culture-specific formatting information.
public
TimeSpan
ToTimeSpan​()
Convert the current <see cref="T:System.TimeOnly" /> instance to a <see cref="T:System.TimeSpan" /> object.
Returns A <see cref="T:System.TimeSpan" /> object spanning to the time specified in the current <see cref="T:System.TimeOnly" /> instance.
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,
DateTimeStyles style,
TimeOnly& result)
public static
bool
TryParse​(ReadOnlySpan<​char> s,
IFormatProvider? provider,
TimeOnly& result)
public static
bool
TryParse​(string s,
IFormatProvider provider,
DateTimeStyles style,
TimeOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
IFormatProvider? provider,
DateTimeStyles style,
TimeOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
ReadOnlySpan<​char> format,
TimeOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
string[] formats,
IFormatProvider provider,
DateTimeStyles style,
TimeOnly& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> s,
string[] formats,
TimeOnly& result)
public static
bool
TryParseExact​(string s,
string format,
IFormatProvider provider,
DateTimeStyles style,
TimeOnly& result)
public static
bool
TryParseExact​(string s,
string[] formats,
IFormatProvider provider,
DateTimeStyles style,
TimeOnly& 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" /> .