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
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
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
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)
value
A positive or negative time interval.
Returns An object whose value is the sum of the time represented by this instance and the time interval represented by value.
Returns a new <see cref="T:System.TimeOnly" /> that adds the value of the specified time span to the value of this instance.
public
TimeOnly
AddHours​(double value)
value
A number of whole and fractional hours. The value parameter can be negative or positive.
Returns An object whose value is the sum of the time represented by this instance and the number of hours represented by value.
Returns a new <see cref="T:System.TimeOnly" /> that adds the specified number of hours to the value of this instance.
public
TimeOnly
AddMinutes​(double value)
value
A number of whole and fractional minutes. The value parameter can be negative or positive.
Returns An object whose value is the sum of the time represented by this instance and the number of minutes represented by value.
Returns a new <see cref="T:System.TimeOnly" /> that adds the specified number of minutes to the value of this instance.
public
int
CompareTo​(object value)
value
A boxed object to compare, or <see langword="null" /> .
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.
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.
public
int
CompareTo​(TimeOnly value)
value
The object to compare to the current instance.
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.
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.
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)
value
The object to compare to this instance.
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" /> .
Returns a value indicating whether this instance is equal to a specified object.
public
bool
Equals​(TimeOnly 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.TimeOnly" /> instance.
public
int
GetHashCode​() Returns A 32-bit signed integer hash code.
Returns the hash code for this instance.
public
bool
IsBetween​(TimeOnly start,
TimeOnly end)
start
The starting time of day, inclusive.
end
The ending time of day, exclusive.
Returns <see langword="true" /> , if the time falls within the range, <see langword="false" /> otherwise.
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.
public
string
ToLongTimeString​() Returns The long time string representation of the current instance.
Converts the value of the current <see cref="T:System.TimeOnly" /> instance to its equivalent long date string representation.
public
string
ToShortTimeString​() Returns The short time string representation of the current instance.
Converts the current <see cref="T:System.TimeOnly" /> instance to its equivalent short time string representation.
public
string
ToString​() Returns The short time string representation of the current instance.
Converts the current <see cref="T:System.TimeOnly" /> instance to its equivalent short time string representation using the formatting conventions of the current culture.
public
string
ToString​(IFormatProvider provider)
provider
The culture-specific formatting information.
Returns A string representation of the current instance as specified by the 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.
public
string
ToString​(string format)
format
A standard or custom time format string.
Returns A string representation of the current instance with the specified format and the formatting conventions of the current culture.
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.
public
string
ToString​(string format,
IFormatProvider provider)
format
A standard or custom time format string.
provider
The culture-specific formatting information.
Returns A string representation of value of the current instance.
Converts the value of the current <see cref="T:System.TimeOnly" /> instance to its equivalent string representation using the specified culture-specific format information.
public
TimeSpan
ToTimeSpan​() Returns A <see cref="T:System.TimeSpan" /> object spanning to the time specified in the current <see cref="T:System.TimeOnly" /> instance.
Convert the current <see cref="T:System.TimeOnly" /> instance to a <see cref="T:System.TimeSpan" /> object.
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" /> .