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.​TimeSpan
Assembly: System.Runtime
Represents a time interval.
Fields and Constants
public const
int
HoursPerDay
Represents the number of hours in 1 day. This field is constant.
public static readonly
TimeSpan
MaxValue
Represents the maximum <see cref="T:System.TimeSpan" /> value. This field is read-only.
public const
long
MicrosecondsPerDay
Represents the number of microseconds in 1 day. This field is constant.
public const
long
MicrosecondsPerHour
Represents the number of microseconds in 1 hour. This field is constant.
public const
long
MicrosecondsPerMillisecond
Represents the number of microseconds in 1 millisecond. This field is constant.
public const
long
MicrosecondsPerMinute
Represents the number of microseconds in 1 minute. This field is constant.
public const
long
MicrosecondsPerSecond
Represents the number of microseconds in 1 second. This field is constant.
public const
long
MillisecondsPerDay
Represents the number of milliseconds in 1 day. This field is constant.
public const
long
MillisecondsPerHour
Represents the number of milliseconds in 1 hour. This field is constant.
public const
long
MillisecondsPerMinute
Represents the number of milliseconds in 1 minute. This field is constant.
public const
long
MillisecondsPerSecond
Represents the number of milliseconds in 1 second. This field is constant.
public const
long
MinutesPerDay
Represents the number of minutes in 1 day. This field is constant.
public const
long
MinutesPerHour
Represents the number of minutes in 1 hour. This field is constant.
public static readonly
TimeSpan
MinValue
Represents the minimum <see cref="T:System.TimeSpan" /> value. This field is read-only.
public const
long
NanosecondsPerTick
Represents the number of nanoseconds per tick. This field is constant.
public const
long
SecondsPerDay
Represents the number of seconds in 1 day. This field is constant.
public const
long
SecondsPerHour
Represents the number of seconds in 1 hour. This field is constant.
public const
long
SecondsPerMinute
Represents the number of seconds in 1 minute. This field is constant.
public const
long
TicksPerDay
Represents the number of ticks in 1 day. This field is constant.
public const
long
TicksPerHour
Represents the number of ticks in 1 hour. This field is constant.
public const
long
TicksPerMicrosecond
Represents the number of ticks in 1 microsecond. This field is constant.
public const
long
TicksPerMillisecond
Represents the number of ticks in 1 millisecond. This field is constant.
public const
long
TicksPerMinute
Represents the number of ticks in 1 minute. This field is constant.
public const
long
TicksPerSecond
Represents the number of ticks in 1 second.
public static readonly
TimeSpan
Zero
Represents the zero <see cref="T:System.TimeSpan" /> value. This field is read-only.
Properties
public
int
Days
Gets the days component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
int
Hours
Gets the hours component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
int
Microseconds
Gets the microseconds component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
int
Milliseconds
Gets the milliseconds component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
int
Minutes
Gets the minutes component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
int
Nanoseconds
Gets the nanoseconds component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
int
Seconds
Gets the seconds component of the time interval represented by the current <see cref="T:System.TimeSpan" /> structure.
public
long
Ticks
Gets the number of ticks that represent the value of the current <see cref="T:System.TimeSpan" /> structure.
public
double
TotalDays
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional days.
public
double
TotalHours
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional hours.
public
double
TotalMicroseconds
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional microseconds.
public
double
TotalMilliseconds
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional milliseconds.
public
double
TotalMinutes
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional minutes.
public
double
TotalNanoseconds
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional nanoseconds.
public
double
TotalSeconds
Gets the value of the current <see cref="T:System.TimeSpan" /> structure expressed in whole and fractional seconds.
Methods
public
TimeSpan
Add​(TimeSpan ts)
ts
The time interval to add.
Returns A new object that represents the value of this instance plus the value of <paramref name="ts" /> .
Returns a new <see cref="T:System.TimeSpan" /> object whose value is the sum of the specified <see cref="T:System.TimeSpan" /> object and this instance.
public
int
CompareTo​(object value)
value
An object to compare, or <see langword="null" /> .
Returns One of the following values.
<list type="table">
<listheader>
<term> Value</term>
<description> Description</description>
</listheader>
<item>
<term> -1</term>
<description> This instance is shorter than <paramref name="value" />.</description>
</item>
<item>
<term> 0</term>
<description> This instance is equal to <paramref name="value" />.</description>
</item>
<item>
<term> 1</term>
<description> This instance is longer than <paramref name="value" />, or <paramref name="value" /> is <see langword="null" />.</description>
</item>
</list>
Compares this instance to a specified object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the specified object.
public
int
CompareTo​(TimeSpan value)
value
An object to compare to this instance.
Returns A signed number indicating the relative values of this instance and <paramref name="value" /> .
<list type="table">
<listheader>
<term> Value</term>
<description> Description</description>
</listheader>
<item>
<term> A negative integer</term>
<description> This instance is shorter than <paramref name="value" />.</description>
</item>
<item>
<term> Zero</term>
<description> This instance is equal to <paramref name="value" />.</description>
</item>
<item>
<term> A positive integer</term>
<description> This instance is longer than <paramref name="value" />.</description>
</item>
</list>
Compares this instance to a specified <see cref="T:System.TimeSpan" /> object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the <see cref="T:System.TimeSpan" /> object.
public
TimeSpan
Divide​(double divisor)
divisor
The divisor or value to be divided by.
Returns A new object that represents the value of this instance divided by the value of <paramref name="divisor" /> .
Returns a new <see cref="T:System.TimeSpan" /> object whose value is the result of dividing this instance by the specified <paramref name="divisor" /> .
public
double
Divide​(TimeSpan ts)
ts
The value to be divided by.
Returns A new value that represents result of dividing this instance by the value of <paramref name="ts" /> .
Returns a new <see cref="T:System.Double" /> value that's the result of dividing this instance by <paramref name="ts" /> .
public
TimeSpan
Duration​() Returns A new object whose value is the absolute value of the current <see cref="T:System.TimeSpan" /> object.
Returns a new <see cref="T:System.TimeSpan" /> object whose value is the absolute value of the current <see cref="T:System.TimeSpan" /> object.
public
bool
Equals​(object value)
value
An object to compare with this instance.
Returns <see langword="true" /> if <paramref name="value" /> is a <see cref="T:System.TimeSpan" /> object that represents the same time interval as the current <see cref="T:System.TimeSpan" /> structure; otherwise, <see langword="false" /> .
Returns a value indicating whether this instance is equal to a specified object.
public
bool
Equals​(TimeSpan obj)
obj
An object to compare with this instance.
Returns <see langword="true" /> if <paramref name="obj" /> represents the same time interval as this instance; otherwise, <see langword="false" /> .
Returns a value indicating whether this instance is equal to a specified <see cref="T:System.TimeSpan" /> object.
public
int
GetHashCode​() Returns A 32-bit signed integer hash code.
Returns a hash code for this instance.
public
TimeSpan
Multiply​(double factor)
factor
The value to be multiplied by.
Returns A new object that represents the value of this instance multiplied by the value of <paramref name="factor" /> .
Returns a new <see cref="T:System.TimeSpan" /> object which value is the result of multiplication of this instance and the specified <paramref name="factor" /> .
public
TimeSpan
Negate​() Returns A new object with the same numeric value as this instance, but with the opposite sign.
Returns a new <see cref="T:System.TimeSpan" /> object whose value is the negated value of this instance.
public
TimeSpan
Subtract​(TimeSpan ts)
ts
The time interval to be subtracted.
Returns A new time interval whose value is the result of the value of this instance minus the value of <paramref name="ts" /> .
Returns a new <see cref="T:System.TimeSpan" /> object whose value is the difference between the specified <see cref="T:System.TimeSpan" /> object and this instance.
public
string
ToString​() Returns The string representation of the current <see cref="T:System.TimeSpan" /> value.
Converts the value of the current <see cref="T:System.TimeSpan" /> object to its equivalent string representation.
public
string
ToString​(string format)
format
A standard or custom <see cref="T:System.TimeSpan" /> format string.
Returns The string representation of the current <see cref="T:System.TimeSpan" /> value in the format specified by the <paramref name="format" /> parameter.
Converts the value of the current <see cref="T:System.TimeSpan" /> object to its equivalent string representation by using the specified format.
public
string
ToString​(string format,
IFormatProvider formatProvider)
format
A standard or custom <see cref="T:System.TimeSpan" /> format string.
formatProvider
An object that supplies culture-specific formatting information.
Returns The string representation of the current <see cref="T:System.TimeSpan" /> value, as specified by <paramref name="format" /> and <paramref name="formatProvider" /> .
Converts the value of the current <see cref="T:System.TimeSpan" /> object to its equivalent string representation by using the specified format and culture-specific formatting information.
public
bool
TryFormat​(Span`1 utf8Destination,
Int32& bytesWritten,
ReadOnlySpan`1 format = null,
IFormatProvider formatProvider = null)
public
bool
TryFormat​(Span`1 destination,
Int32& charsWritten,
ReadOnlySpan`1 format = null,
IFormatProvider formatProvider = 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" /> .