← Interactive API Explorer
Namespace: System

TimeSpan

Represents a time interval.

Properties (11)

long Ticks
Gets the number of ticks that represent the value of the current TimeSpan structure.
Value: The number of ticks contained in this instance.
int Days
Gets the days component of the time interval represented by the current TimeSpan structure.
Value: The day component of this instance. The return value can be positive or negative.
int Hours
Gets the hours component of the time interval represented by the current TimeSpan structure.
Value: The hour component of the current TimeSpan structure. The return value ranges from -23 through 23.
int Minutes
Gets the minutes component of the time interval represented by the current TimeSpan structure.
Value: The minute component of the current TimeSpan structure. The return value ranges from -59 through 59.
int Seconds
Gets the seconds component of the time interval represented by the current TimeSpan structure.
Value: The second component of the current TimeSpan structure. The return value ranges from -59 through 59.
int Milliseconds
Gets the milliseconds component of the time interval represented by the current TimeSpan structure.
Value: The millisecond component of the current TimeSpan structure. The return value ranges from -999 through 999.
double TotalDays
Gets the value of the current TimeSpan structure expressed in whole and fractional days.
Value: The total number of days represented by this instance.
double TotalHours
Gets the value of the current TimeSpan structure expressed in whole and fractional hours.
Value: The total number of hours represented by this instance.
double TotalMilliseconds
Gets the value of the current TimeSpan structure expressed in whole and fractional milliseconds.
Value: The total number of milliseconds represented by this instance.
double TotalMinutes
Gets the value of the current TimeSpan structure expressed in whole and fractional minutes.
Value: The total number of minutes represented by this instance.
double TotalSeconds
Gets the value of the current TimeSpan structure expressed in whole and fractional seconds.
Value: The total number of seconds represented by this instance.

Methods (16)

TimeSpan(Int64)Constructor
Initializes a new instance of the TimeSpan structure to the specified number of ticks.
ParameterDescription
ticksA time period expressed in 100-nanosecond units.
TimeSpan(Int32,Int32,Int32)Constructor
Initializes a new instance of the TimeSpan structure to a specified number of hours, minutes, and seconds.
ParameterDescription
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
TimeSpan(Int32,Int32,Int32,Int32,Int32)Constructor
Initializes a new instance of the TimeSpan structure to a specified number of days, hours, minutes, seconds, and milliseconds.
ParameterDescription
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
millisecondsNumber of milliseconds.
TimeSpan(Int32,Int32,Int32,Int32)Constructor
Initializes a new instance of the TimeSpan structure to a specified number of days, hours, minutes, and seconds.
ParameterDescription
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
TimeSpan Add(TimeSpan)
Returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.
ParameterDescription
tsThe time interval to add.
Returns: A new object that represents the value of this instance plus the value of ts.
int Compare(TimeSpan,TimeSpan)
Compares two TimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.
ParameterDescription
t1The first time interval to compare.
t2The second time interval to compare.
Returns: One of the following values. Value Description -1 t1 is shorter than t2. 0 t1 is equal to t2. 1 t1 is longer than t2.
int CompareTo(TimeSpan)
Compares this instance to a specified TimeSpan object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the TimeSpan object.
ParameterDescription
valueAn object to compare to this instance.
Returns: A signed number indicating the relative values of this instance and value. Value Description A negative integer This instance is shorter than value. Zero This instance is equal to value. A positive integer This instance is longer than value.
TimeSpan FromDays(Double)
Returns a TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.
ParameterDescription
valueA number of days, accurate to the nearest millisecond.
Returns: An object that represents value.
TimeSpan Duration
Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.
Returns: A new object whose value is the absolute value of the current TimeSpan object.
TimeSpan FromHours(Double)
Returns a TimeSpan that represents a specified number of hours, where the specification is accurate to the nearest millisecond.
ParameterDescription
valueA number of hours accurate to the nearest millisecond.
Returns: An object that represents value.
TimeSpan FromMilliseconds(Double)
Returns a TimeSpan that represents a specified number of milliseconds.
ParameterDescription
valueA number of milliseconds.
Returns: An object that represents value.
TimeSpan FromMinutes(Double)
Returns a TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.
ParameterDescription
valueA number of minutes, accurate to the nearest millisecond.
Returns: An object that represents value.
TimeSpan Negate
Returns a new TimeSpan object whose value is the negated value of this instance.
Returns: A new object with the same numeric value as this instance, but with the opposite sign.
TimeSpan FromSeconds(Double)
Returns a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
ParameterDescription
valueA number of seconds, accurate to the nearest millisecond.
Returns: An object that represents value.
TimeSpan Subtract(TimeSpan)
Returns a new TimeSpan object whose value is the difference between the specified TimeSpan object and this instance.
ParameterDescription
tsThe 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 ts.
TimeSpan FromTicks(Int64)
Returns a TimeSpan that represents a specified time, where the specification is in units of ticks.
ParameterDescription
valueA number of ticks that represent a time.
Returns: An object that represents value.