mscorlib(4.0.0.0) API with additions
System.TimeSpan Struct Reference

Represents a time interval.To browse the .NET Framework source code for this type, see the Reference Source. More...

Inheritance diagram for System.TimeSpan:
[legend]
Collaboration diagram for System.TimeSpan:
[legend]

Public Member Functions

 TimeSpan (long ticks)
 Initializes a new instance of the T:System.TimeSpan structure to the specified number of ticks. More...
 
 TimeSpan (int hours, int minutes, int seconds)
 Initializes a new instance of the T:System.TimeSpan structure to a specified number of hours, minutes, and seconds. More...
 
 TimeSpan (int days, int hours, int minutes, int seconds)
 Initializes a new instance of the T:System.TimeSpan structure to a specified number of days, hours, minutes, and seconds. More...
 
 TimeSpan (int days, int hours, int minutes, int seconds, int milliseconds)
 Initializes a new instance of the T:System.TimeSpan structure to a specified number of days, hours, minutes, seconds, and milliseconds. More...
 
TimeSpan Add (TimeSpan ts)
 Returns a new T:System.TimeSpan object whose value is the sum of the specified T:System.TimeSpan object and this instance. More...
 
int CompareTo (object value)
 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. More...
 
int CompareTo (TimeSpan value)
 Compares this instance to a specified T:System.TimeSpan object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the T:System.TimeSpan object. More...
 
TimeSpan Duration ()
 Returns a new T:System.TimeSpan object whose value is the absolute value of the current T:System.TimeSpan object. More...
 
override bool Equals (object value)
 Returns a value indicating whether this instance is equal to a specified object. More...
 
bool Equals (TimeSpan obj)
 Returns a value indicating whether this instance is equal to a specified T:System.TimeSpan object. More...
 
override int GetHashCode ()
 Returns a hash code for this instance. More...
 
TimeSpan Negate ()
 Returns a new T:System.TimeSpan object whose value is the negated value of this instance. More...
 
TimeSpan Subtract (TimeSpan ts)
 Returns a new T:System.TimeSpan object whose value is the difference between the specified T:System.TimeSpan object and this instance. More...
 
override string ToString ()
 Converts the value of the current T:System.TimeSpan object to its equivalent string representation. More...
 
string ToString (string format)
 Converts the value of the current T:System.TimeSpan object to its equivalent string representation by using the specified format. More...
 
string ToString (string format, IFormatProvider formatProvider)
 Converts the value of the current T:System.TimeSpan object to its equivalent string representation by using the specified format and culture-specific formatting information. More...
 
- Public Member Functions inherited from System.IEquatable< TimeSpan >
bool Equals (T other)
 Indicates whether the current object is equal to another object of the same type. More...
 

Static Public Member Functions

static int Compare (TimeSpan t1, TimeSpan t2)
 Compares two T:System.TimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value. More...
 
static TimeSpan FromDays (double value)
 Returns a T:System.TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond. More...
 
static bool Equals (TimeSpan t1, TimeSpan t2)
 Returns a value that indicates whether two specified instances of T:System.TimeSpan are equal. More...
 
static TimeSpan FromHours (double value)
 Returns a T:System.TimeSpan that represents a specified number of hours, where the specification is accurate to the nearest millisecond. More...
 
static TimeSpan FromMilliseconds (double value)
 Returns a T:System.TimeSpan that represents a specified number of milliseconds. More...
 
static TimeSpan FromMinutes (double value)
 Returns a T:System.TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond. More...
 
static TimeSpan FromSeconds (double value)
 Returns a T:System.TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond. More...
 
static TimeSpan FromTicks (long value)
 Returns a T:System.TimeSpan that represents a specified time, where the specification is in units of ticks. More...
 
static internal long TimeToTicks (int hour, int minute, int second)
 
static TimeSpan Parse (string s)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent. More...
 
static TimeSpan Parse (string input, IFormatProvider formatProvider)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified culture-specific format information. More...
 
static TimeSpan ParseExact (string input, string format, IFormatProvider formatProvider)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly. More...
 
static TimeSpan ParseExact (string input, string[] formats, IFormatProvider formatProvider)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified array of format strings and culture-specific format information. The format of the string representation must match one of the specified formats exactly. More...
 
static TimeSpan ParseExact (string input, string format, IFormatProvider formatProvider, TimeSpanStyles styles)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format, culture-specific format information, and styles. The format of the string representation must match the specified format exactly. More...
 
static TimeSpan ParseExact (string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified formats, culture-specific format information, and styles. The format of the string representation must match one of the specified formats exactly. More...
 
static bool TryParse (string s, out TimeSpan result)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent and returns a value that indicates whether the conversion succeeded. More...
 
static bool TryParse (string input, IFormatProvider formatProvider, out TimeSpan result)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified culture-specific formatting information, and returns a value that indicates whether the conversion succeeded. More...
 
static bool TryParseExact (string input, string format, IFormatProvider formatProvider, out TimeSpan result)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format and culture-specific format information, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match the specified format exactly. More...
 
static bool TryParseExact (string input, string[] formats, IFormatProvider formatProvider, out TimeSpan result)
 Converts the specified string representation of a time interval to its T:System.TimeSpan equivalent by using the specified formats and culture-specific format information, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match one of the specified formats exactly. More...
 
static bool TryParseExact (string input, string format, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
 Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format, culture-specific format information, and styles, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match the specified format exactly. More...
 
static bool TryParseExact (string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
 Converts the specified string representation of a time interval to its T:System.TimeSpan equivalent by using the specified formats, culture-specific format information, and styles, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match one of the specified formats exactly. More...
 
static TimeSpan operator - (TimeSpan t)
 Returns a T:System.TimeSpan whose value is the negated value of the specified instance. More...
 
static TimeSpan operator - (TimeSpan t1, TimeSpan t2)
 Subtracts a specified T:System.TimeSpan from another specified T:System.TimeSpan. More...
 
static TimeSpan operator+ (TimeSpan t)
 Returns the specified instance of T:System.TimeSpan. More...
 
static TimeSpan operator+ (TimeSpan t1, TimeSpan t2)
 Adds two specified T:System.TimeSpan instances. More...
 
static bool operator== (TimeSpan t1, TimeSpan t2)
 Indicates whether two T:System.TimeSpan instances are equal. More...
 
static bool operator != (TimeSpan t1, TimeSpan t2)
 Indicates whether two T:System.TimeSpan instances are not equal. More...
 
static bool operator< (TimeSpan t1, TimeSpan t2)
 Indicates whether a specified T:System.TimeSpan is less than another specified T:System.TimeSpan. More...
 
static bool operator<= (TimeSpan t1, TimeSpan t2)
 Indicates whether a specified T:System.TimeSpan is less than or equal to another specified T:System.TimeSpan. More...
 
static bool operator > (TimeSpan t1, TimeSpan t2)
 Indicates whether a specified T:System.TimeSpan is greater than another specified T:System.TimeSpan. More...
 
static bool operator >= (TimeSpan t1, TimeSpan t2)
 Indicates whether a specified T:System.TimeSpan is greater than or equal to another specified T:System.TimeSpan. More...
 

Public Attributes

const long TicksPerMillisecond = 10000L
 Represents the number of ticks in 1 millisecond. This field is constant. More...
 
const long TicksPerSecond = 10000000L
 Represents the number of ticks in 1 second. More...
 
const long TicksPerMinute = 600000000L
 Represents the number of ticks in 1 minute. This field is constant. More...
 
const long TicksPerHour = 36000000000L
 Represents the number of ticks in 1 hour. This field is constant. More...
 
const long TicksPerDay = 864000000000L
 Represents the number of ticks in 1 day. This field is constant. More...
 
internal const long MaxSeconds = 922337203685L
 
internal const long MinSeconds = -922337203685L
 
internal const long MaxMilliSeconds = 922337203685477L
 
internal const long MinMilliSeconds = -922337203685477L
 
internal const long TicksPerTenthSecond = 1000000L
 
internal long _ticks
 

Static Public Attributes

static readonly TimeSpan Zero = new TimeSpan(0L)
 Represents the zero T:System.TimeSpan value. This field is read-only. More...
 
static readonly TimeSpan MaxValue = new TimeSpan(long.MaxValue)
 Represents the maximum T:System.TimeSpan value. This field is read-only. More...
 
static readonly TimeSpan MinValue = new TimeSpan(long.MinValue)
 Represents the minimum T:System.TimeSpan value. This field is read-only. More...
 

Properties

long Ticks [get]
 Gets the number of ticks that represent the value of the current T:System.TimeSpan structure. More...
 
int Days [get]
 Gets the days component of the time interval represented by the current T:System.TimeSpan structure. More...
 
int Hours [get]
 Gets the hours component of the time interval represented by the current T:System.TimeSpan structure. More...
 
int Milliseconds [get]
 Gets the milliseconds component of the time interval represented by the current T:System.TimeSpan structure. More...
 
int Minutes [get]
 Gets the minutes component of the time interval represented by the current T:System.TimeSpan structure. More...
 
int Seconds [get]
 Gets the seconds component of the time interval represented by the current T:System.TimeSpan structure. More...
 
double TotalDays [get]
 Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional days. More...
 
double TotalHours [get]
 Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional hours. More...
 
double TotalMilliseconds [get]
 Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional milliseconds. More...
 
double TotalMinutes [get]
 Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional minutes. More...
 
double TotalSeconds [get]
 Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional seconds. More...
 

Detailed Description

Represents a time interval.To browse the .NET Framework source code for this type, see the Reference Source.

Definition at line 12 of file TimeSpan.cs.

Constructor & Destructor Documentation

◆ TimeSpan() [1/4]

System.TimeSpan.TimeSpan ( long  ticks)

Initializes a new instance of the T:System.TimeSpan structure to the specified number of ticks.

Parameters
ticksA time period expressed in 100-nanosecond units.

Definition at line 237 of file TimeSpan.cs.

◆ TimeSpan() [2/4]

System.TimeSpan.TimeSpan ( int  hours,
int  minutes,
int  seconds 
)

Initializes a new instance of the T:System.TimeSpan structure to a specified number of hours, minutes, and seconds.

Parameters
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe parameters specify a T:System.TimeSpan value less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 248 of file TimeSpan.cs.

◆ TimeSpan() [3/4]

System.TimeSpan.TimeSpan ( int  days,
int  hours,
int  minutes,
int  seconds 
)

Initializes a new instance of the T:System.TimeSpan structure to a specified number of days, hours, minutes, and seconds.

Parameters
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe parameters specify a T:System.TimeSpan value less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 260 of file TimeSpan.cs.

◆ TimeSpan() [4/4]

System.TimeSpan.TimeSpan ( int  days,
int  hours,
int  minutes,
int  seconds,
int  milliseconds 
)

Initializes a new instance of the T:System.TimeSpan structure to a specified number of days, hours, minutes, seconds, and milliseconds.

Parameters
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
millisecondsNumber of milliseconds.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe parameters specify a T:System.TimeSpan value less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 273 of file TimeSpan.cs.

Member Function Documentation

◆ Add()

TimeSpan System.TimeSpan.Add ( TimeSpan  ts)

Returns a new T:System.TimeSpan object whose value is the sum of the specified T:System.TimeSpan object and this instance.

Parameters
tsThe time interval to add.
Returns
A new object that represents the value of this instance plus the value of ts .
Exceptions
T:System.OverflowExceptionThe resulting T:System.TimeSpan is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 289 of file TimeSpan.cs.

◆ Compare()

static int System.TimeSpan.Compare ( TimeSpan  t1,
TimeSpan  t2 
)
static

Compares two T:System.TimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.

Parameters
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 .

Definition at line 307 of file TimeSpan.cs.

◆ CompareTo() [1/2]

int System.TimeSpan.CompareTo ( object  value)

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.

Parameters
valueAn object to compare, or null.
Returns
One of the following values.Value Description -1 This instance is shorter than value . 0 This instance is equal to value . 1 This instance is longer than value .-or- value is null.
Exceptions
T:System.ArgumentExceptionvalue is not a T:System.TimeSpan.

Definition at line 326 of file TimeSpan.cs.

◆ CompareTo() [2/2]

int System.TimeSpan.CompareTo ( TimeSpan  value)

Compares this instance to a specified T:System.TimeSpan object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the T:System.TimeSpan object.

Parameters
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 .

Definition at line 352 of file TimeSpan.cs.

◆ Duration()

TimeSpan System.TimeSpan.Duration ( )

Returns a new T:System.TimeSpan object whose value is the absolute value of the current T:System.TimeSpan object.

Returns
A new object whose value is the absolute value of the current T:System.TimeSpan object.
Exceptions
T:System.OverflowExceptionThe value of this instance is F:System.TimeSpan.MinValue.

Definition at line 385 of file TimeSpan.cs.

◆ Equals() [1/3]

override bool System.TimeSpan.Equals ( object  value)

Returns a value indicating whether this instance is equal to a specified object.

Parameters
valueAn object to compare with this instance.
Returns
true if value is a T:System.TimeSpan object that represents the same time interval as the current T:System.TimeSpan structure; otherwise, false.

Definition at line 399 of file TimeSpan.cs.

◆ Equals() [2/3]

bool System.TimeSpan.Equals ( TimeSpan  obj)

Returns a value indicating whether this instance is equal to a specified T:System.TimeSpan object.

Parameters
objAn object to compare with this instance.
Returns
true if obj represents the same time interval as this instance; otherwise, false.

Definition at line 413 of file TimeSpan.cs.

◆ Equals() [3/3]

static bool System.TimeSpan.Equals ( TimeSpan  t1,
TimeSpan  t2 
)
static

Returns a value that indicates whether two specified instances of T:System.TimeSpan are equal.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the values of t1 and t2 are equal; otherwise, false.

Definition at line 424 of file TimeSpan.cs.

◆ FromDays()

static TimeSpan System.TimeSpan.FromDays ( double  value)
static

Returns a T:System.TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of days, accurate to the nearest millisecond.
Returns
An object that represents value .
Exceptions
T:System.OverflowExceptionvalue is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue. -or- value is F:System.Double.PositiveInfinity.-or- value is F:System.Double.NegativeInfinity.
T:System.ArgumentExceptionvalue is equal to F:System.Double.NaN.

Definition at line 376 of file TimeSpan.cs.

◆ FromHours()

static TimeSpan System.TimeSpan.FromHours ( double  value)
static

Returns a T:System.TimeSpan that represents a specified number of hours, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of hours accurate to the nearest millisecond.
Returns
An object that represents value .
Exceptions
T:System.OverflowExceptionvalue is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue. -or- value is F:System.Double.PositiveInfinity.-or- value is F:System.Double.NegativeInfinity.
T:System.ArgumentExceptionvalue is equal to F:System.Double.NaN.

Definition at line 447 of file TimeSpan.cs.

◆ FromMilliseconds()

static TimeSpan System.TimeSpan.FromMilliseconds ( double  value)
static

Returns a T:System.TimeSpan that represents a specified number of milliseconds.

Parameters
valueA number of milliseconds.
Returns
An object that represents value .
Exceptions
T:System.OverflowExceptionvalue is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- value is F:System.Double.PositiveInfinity.-or- value is F:System.Double.NegativeInfinity.
T:System.ArgumentExceptionvalue is equal to F:System.Double.NaN.

Definition at line 477 of file TimeSpan.cs.

◆ FromMinutes()

static TimeSpan System.TimeSpan.FromMinutes ( double  value)
static

Returns a T:System.TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of minutes, accurate to the nearest millisecond.
Returns
An object that represents value .
Exceptions
T:System.OverflowExceptionvalue is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- value is F:System.Double.PositiveInfinity.-or- value is F:System.Double.NegativeInfinity.
T:System.ArgumentExceptionvalue is equal to F:System.Double.NaN.

Definition at line 492 of file TimeSpan.cs.

◆ FromSeconds()

static TimeSpan System.TimeSpan.FromSeconds ( double  value)
static

Returns a T:System.TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of seconds, accurate to the nearest millisecond.
Returns
An object that represents value .
Exceptions
T:System.OverflowExceptionvalue is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- value is F:System.Double.PositiveInfinity.-or- value is F:System.Double.NegativeInfinity.
T:System.ArgumentExceptionvalue is equal to F:System.Double.NaN.

Definition at line 520 of file TimeSpan.cs.

◆ FromTicks()

static TimeSpan System.TimeSpan.FromTicks ( long  value)
static

Returns a T:System.TimeSpan that represents a specified time, where the specification is in units of ticks.

Parameters
valueA number of ticks that represent a time.
Returns
An object that represents value .

Definition at line 545 of file TimeSpan.cs.

◆ GetHashCode()

override int System.TimeSpan.GetHashCode ( )

Returns a hash code for this instance.

Returns
A 32-bit signed integer hash code.

Definition at line 432 of file TimeSpan.cs.

◆ Negate()

TimeSpan System.TimeSpan.Negate ( )

Returns a new T:System.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.
Exceptions
T:System.OverflowExceptionThe negated value of this instance cannot be represented by a T:System.TimeSpan; that is, the value of this instance is F:System.TimeSpan.MinValue.

Definition at line 501 of file TimeSpan.cs.

◆ operator !=()

static bool System.TimeSpan.operator != ( TimeSpan  t1,
TimeSpan  t2 
)
static

Indicates whether two T:System.TimeSpan instances are not equal.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the values of t1 and t2 are not equal; otherwise, false.

Definition at line 841 of file TimeSpan.cs.

◆ operator -() [1/2]

static TimeSpan System.TimeSpan.operator - ( TimeSpan  t)
static

Returns a T:System.TimeSpan whose value is the negated value of the specified instance.

Parameters
tThe time interval to be negated.
Returns
An object that has the same numeric value as this instance, but the opposite sign.
Exceptions
T:System.OverflowExceptionThe negated value of this instance cannot be represented by a T:System.TimeSpan; that is, the value of this instance is F:System.TimeSpan.MinValue.

Definition at line 784 of file TimeSpan.cs.

◆ operator -() [2/2]

static TimeSpan System.TimeSpan.operator - ( TimeSpan  t1,
TimeSpan  t2 
)
static

Subtracts a specified T:System.TimeSpan from another specified T:System.TimeSpan.

Parameters
t1The minuend.
t2The subtrahend.
Returns
An object whose value is the result of the value of t1 minus the value of t2 .
Exceptions
T:System.OverflowExceptionThe return value is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 799 of file TimeSpan.cs.

◆ operator >()

static bool System.TimeSpan.operator > ( TimeSpan  t1,
TimeSpan  t2 
)
static

Indicates whether a specified T:System.TimeSpan is greater than another specified T:System.TimeSpan.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the value of t1 is greater than the value of t2 ; otherwise, false.

Definition at line 874 of file TimeSpan.cs.

◆ operator >=()

static bool System.TimeSpan.operator >= ( TimeSpan  t1,
TimeSpan  t2 
)
static

Indicates whether a specified T:System.TimeSpan is greater than or equal to another specified T:System.TimeSpan.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the value of t1 is greater than or equal to the value of t2 ; otherwise, false.

Definition at line 885 of file TimeSpan.cs.

◆ operator+() [1/2]

static TimeSpan System.TimeSpan.operator+ ( TimeSpan  t)
static

Returns the specified instance of T:System.TimeSpan.

Parameters
tThe time interval to return.
Returns
The time interval specified by t .

Definition at line 808 of file TimeSpan.cs.

◆ operator+() [2/2]

static TimeSpan System.TimeSpan.operator+ ( TimeSpan  t1,
TimeSpan  t2 
)
static

Adds two specified T:System.TimeSpan instances.

Parameters
t1The first time interval to add.
t2The second time interval to add.
Returns
An object whose value is the sum of the values of t1 and t2 .
Exceptions
T:System.OverflowExceptionThe resulting T:System.TimeSpan is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 819 of file TimeSpan.cs.

◆ operator<()

static bool System.TimeSpan.operator< ( TimeSpan  t1,
TimeSpan  t2 
)
static

Indicates whether a specified T:System.TimeSpan is less than another specified T:System.TimeSpan.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the value of t1 is less than the value of t2 ; otherwise, false.

Definition at line 852 of file TimeSpan.cs.

◆ operator<=()

static bool System.TimeSpan.operator<= ( TimeSpan  t1,
TimeSpan  t2 
)
static

Indicates whether a specified T:System.TimeSpan is less than or equal to another specified T:System.TimeSpan.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the value of t1 is less than or equal to the value of t2 ; otherwise, false.

Definition at line 863 of file TimeSpan.cs.

◆ operator==()

static bool System.TimeSpan.operator== ( TimeSpan  t1,
TimeSpan  t2 
)
static

Indicates whether two T:System.TimeSpan instances are equal.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the values of t1 and t2 are equal; otherwise, false.

Definition at line 830 of file TimeSpan.cs.

◆ Parse() [1/2]

static TimeSpan System.TimeSpan.Parse ( string  s)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent.

Parameters
sA string that specifies the time interval to convert.
Returns
A time interval that corresponds to s .
Exceptions
T:System.ArgumentNullExceptions is null.
T:System.FormatExceptions has an invalid format.
T:System.OverflowExceptions represents a number that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- At least one of the days, hours, minutes, or seconds components is outside its valid range.

Definition at line 570 of file TimeSpan.cs.

◆ Parse() [2/2]

static TimeSpan System.TimeSpan.Parse ( string  input,
IFormatProvider  formatProvider 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified culture-specific format information.

Parameters
inputA string that specifies the time interval to convert.
formatProviderAn object that supplies culture-specific formatting information.
Returns
A time interval that corresponds to input , as specified by formatProvider .
Exceptions
T:System.ArgumentNullExceptioninput is null.
T:System.FormatExceptioninput has an invalid format.
T:System.OverflowExceptioninput represents a number that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- At least one of the days, hours, minutes, or seconds components in input is outside its valid range.

Definition at line 586 of file TimeSpan.cs.

◆ ParseExact() [1/4]

static TimeSpan System.TimeSpan.ParseExact ( string  input,
string  format,
IFormatProvider  formatProvider 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.

Parameters
inputA string that specifies the time interval to convert.
formatA standard or custom format string that defines the required format of input .
formatProviderAn object that provides culture-specific formatting information.
Returns
A time interval that corresponds to input , as specified by format and formatProvider .
Exceptions
T:System.ArgumentNullExceptioninput is null.
T:System.FormatExceptioninput has an invalid format.
T:System.OverflowExceptioninput represents a number that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- At least one of the days, hours, minutes, or seconds components in input is outside its valid range.

Definition at line 603 of file TimeSpan.cs.

◆ ParseExact() [2/4]

static TimeSpan System.TimeSpan.ParseExact ( string  input,
string []  formats,
IFormatProvider  formatProvider 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified array of format strings and culture-specific format information. The format of the string representation must match one of the specified formats exactly.

Parameters
inputA string that specifies the time interval to convert.
formatsA array of standard or custom format strings that defines the required format of input .
formatProviderAn object that provides culture-specific formatting information.
Returns
A time interval that corresponds to input , as specified by formats and formatProvider .
Exceptions
T:System.ArgumentNullExceptioninput is null.
T:System.FormatExceptioninput has an invalid format.
T:System.OverflowExceptioninput represents a number that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- At least one of the days, hours, minutes, or seconds components in input is outside its valid range.

Definition at line 620 of file TimeSpan.cs.

◆ ParseExact() [3/4]

static TimeSpan System.TimeSpan.ParseExact ( string  input,
string  format,
IFormatProvider  formatProvider,
TimeSpanStyles  styles 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format, culture-specific format information, and styles. The format of the string representation must match the specified format exactly.

Parameters
inputA string that specifies the time interval to convert.
formatA standard or custom format string that defines the required format of input .
formatProviderAn object that provides culture-specific formatting information.
stylesA bitwise combination of enumeration values that defines the style elements that may be present in input .
Returns
A time interval that corresponds to input , as specified by format , formatProvider , and styles .
Exceptions
T:System.ArgumentExceptionstyles is an invalid T:System.Globalization.TimeSpanStyles value.
T:System.ArgumentNullExceptioninput is null.
T:System.FormatExceptioninput has an invalid format.
T:System.OverflowExceptioninput represents a number that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- At least one of the days, hours, minutes, or seconds components in input is outside its valid range.

Definition at line 640 of file TimeSpan.cs.

◆ ParseExact() [4/4]

static TimeSpan System.TimeSpan.ParseExact ( string  input,
string []  formats,
IFormatProvider  formatProvider,
TimeSpanStyles  styles 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified formats, culture-specific format information, and styles. The format of the string representation must match one of the specified formats exactly.

Parameters
inputA string that specifies the time interval to convert.
formatsA array of standard or custom format strings that define the required format of input .
formatProviderAn object that provides culture-specific formatting information.
stylesA bitwise combination of enumeration values that defines the style elements that may be present in input.
Returns
A time interval that corresponds to input , as specified by formats , formatProvider , and styles .
Exceptions
T:System.ArgumentExceptionstyles is an invalid T:System.Globalization.TimeSpanStyles value.
T:System.ArgumentNullExceptioninput is null.
T:System.FormatExceptioninput has an invalid format.
T:System.OverflowExceptioninput represents a number that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.-or- At least one of the days, hours, minutes, or seconds components in input is outside its valid range.

Definition at line 661 of file TimeSpan.cs.

◆ Subtract()

TimeSpan System.TimeSpan.Subtract ( TimeSpan  ts)

Returns a new T:System.TimeSpan object whose value is the difference between the specified T:System.TimeSpan object and this instance.

Parameters
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 .
Exceptions
T:System.OverflowExceptionThe return value is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue.

Definition at line 531 of file TimeSpan.cs.

◆ ToString() [1/3]

override string System.TimeSpan.ToString ( )

Converts the value of the current T:System.TimeSpan object to its equivalent string representation.

Returns
The string representation of the current T:System.TimeSpan value.

Definition at line 749 of file TimeSpan.cs.

◆ ToString() [2/3]

string System.TimeSpan.ToString ( string  format)

Converts the value of the current T:System.TimeSpan object to its equivalent string representation by using the specified format.

Parameters
formatA standard or custom T:System.TimeSpan format string.
Returns
The string representation of the current T:System.TimeSpan value in the format specified by the format parameter.
Exceptions
T:System.FormatExceptionThe format parameter is not recognized or is not supported.

Definition at line 759 of file TimeSpan.cs.

◆ ToString() [3/3]

string System.TimeSpan.ToString ( string  format,
IFormatProvider  formatProvider 
)

Converts the value of the current T:System.TimeSpan object to its equivalent string representation by using the specified format and culture-specific formatting information.

Parameters
formatA standard or custom T:System.TimeSpan format string.
formatProviderAn object that supplies culture-specific formatting information.
Returns
The string representation of the current T:System.TimeSpan value, as specified by format and formatProvider .
Exceptions
T:System.FormatExceptionThe format parameter is not recognized or is not supported.

Implements System.IFormattable.

Definition at line 770 of file TimeSpan.cs.

◆ TryParse() [1/2]

static bool System.TimeSpan.TryParse ( string  s,
out TimeSpan  result 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent and returns a value that indicates whether the conversion succeeded.

Parameters
sA string that specifies the time interval to convert.
resultWhen this method returns, contains an object that represents the time interval specified by s , or F:System.TimeSpan.Zero if the conversion failed. This parameter is passed uninitialized.
Returns
true if s was converted successfully; otherwise, false. This operation returns false if the s parameter is null or F:System.String.Empty, has an invalid format, represents a time interval that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue, or has at least one days, hours, minutes, or seconds component outside its valid range.

Definition at line 673 of file TimeSpan.cs.

◆ TryParse() [2/2]

static bool System.TimeSpan.TryParse ( string  input,
IFormatProvider  formatProvider,
out TimeSpan  result 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified culture-specific formatting information, and returns a value that indicates whether the conversion succeeded.

Parameters
inputA string that specifies the time interval to convert.
formatProviderAn object that supplies culture-specific formatting information.
resultWhen this method returns, contains an object that represents the time interval specified by input , or F:System.TimeSpan.Zero if the conversion failed. This parameter is passed uninitialized.
Returns
true if input was converted successfully; otherwise, false. This operation returns false if the input parameter is null or F:System.String.Empty, has an invalid format, represents a time interval that is less than F:System.TimeSpan.MinValue or greater than F:System.TimeSpan.MaxValue, or has at least one days, hours, minutes, or seconds component outside its valid range.

Definition at line 685 of file TimeSpan.cs.

◆ TryParseExact() [1/4]

static bool System.TimeSpan.TryParseExact ( string  input,
string  format,
IFormatProvider  formatProvider,
out TimeSpan  result 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format and culture-specific format information, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match the specified format exactly.

Parameters
inputA string that specifies the time interval to convert.
formatA standard or custom format string that defines the required format of input .
formatProviderAn object that supplies culture-specific formatting information.
resultWhen this method returns, contains an object that represents the time interval specified by input , or F:System.TimeSpan.Zero if the conversion failed. This parameter is passed uninitialized.
Returns
true if input was converted successfully; otherwise, false.

Definition at line 698 of file TimeSpan.cs.

◆ TryParseExact() [2/4]

static bool System.TimeSpan.TryParseExact ( string  input,
string []  formats,
IFormatProvider  formatProvider,
out TimeSpan  result 
)
static

Converts the specified string representation of a time interval to its T:System.TimeSpan equivalent by using the specified formats and culture-specific format information, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match one of the specified formats exactly.

Parameters
inputA string that specifies the time interval to convert.
formatsA array of standard or custom format strings that define the acceptable formats of input .
formatProviderAn object that provides culture-specific formatting information.
resultWhen this method returns, contains an object that represents the time interval specified by input , or F:System.TimeSpan.Zero if the conversion failed. This parameter is passed uninitialized.
Returns
true if input was converted successfully; otherwise, false.

Definition at line 711 of file TimeSpan.cs.

◆ TryParseExact() [3/4]

static bool System.TimeSpan.TryParseExact ( string  input,
string  format,
IFormatProvider  formatProvider,
TimeSpanStyles  styles,
out TimeSpan  result 
)
static

Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using the specified format, culture-specific format information, and styles, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match the specified format exactly.

Parameters
inputA string that specifies the time interval to convert.
formatA standard or custom format string that defines the required format of input .
formatProviderAn object that provides culture-specific formatting information.
stylesOne or more enumeration values that indicate the style of input .
resultWhen this method returns, contains an object that represents the time interval specified by input , or F:System.TimeSpan.Zero if the conversion failed. This parameter is passed uninitialized.
Returns
true if input was converted successfully; otherwise, false.

Definition at line 725 of file TimeSpan.cs.

◆ TryParseExact() [4/4]

static bool System.TimeSpan.TryParseExact ( string  input,
string []  formats,
IFormatProvider  formatProvider,
TimeSpanStyles  styles,
out TimeSpan  result 
)
static

Converts the specified string representation of a time interval to its T:System.TimeSpan equivalent by using the specified formats, culture-specific format information, and styles, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match one of the specified formats exactly.

Parameters
inputA string that specifies the time interval to convert.
formatsA array of standard or custom format strings that define the acceptable formats of input .
formatProviderAn object that supplies culture-specific formatting information.
stylesOne or more enumeration values that indicate the style of input .
resultWhen this method returns, contains an object that represents the time interval specified by input , or F:System.TimeSpan.Zero if the conversion failed. This parameter is passed uninitialized.
Returns
true if input was converted successfully; otherwise, false.

Definition at line 740 of file TimeSpan.cs.

Member Data Documentation

◆ MaxValue

readonly TimeSpan System.TimeSpan.MaxValue = new TimeSpan(long.MaxValue)
static

Represents the maximum T:System.TimeSpan value. This field is read-only.

Definition at line 68 of file TimeSpan.cs.

◆ MinValue

readonly TimeSpan System.TimeSpan.MinValue = new TimeSpan(long.MinValue)
static

Represents the minimum T:System.TimeSpan value. This field is read-only.

Definition at line 72 of file TimeSpan.cs.

◆ TicksPerDay

const long System.TimeSpan.TicksPerDay = 864000000000L

Represents the number of ticks in 1 day. This field is constant.

Definition at line 40 of file TimeSpan.cs.

◆ TicksPerHour

const long System.TimeSpan.TicksPerHour = 36000000000L

Represents the number of ticks in 1 hour. This field is constant.

Definition at line 34 of file TimeSpan.cs.

◆ TicksPerMillisecond

const long System.TimeSpan.TicksPerMillisecond = 10000L

Represents the number of ticks in 1 millisecond. This field is constant.

Definition at line 16 of file TimeSpan.cs.

◆ TicksPerMinute

const long System.TimeSpan.TicksPerMinute = 600000000L

Represents the number of ticks in 1 minute. This field is constant.

Definition at line 28 of file TimeSpan.cs.

◆ TicksPerSecond

const long System.TimeSpan.TicksPerSecond = 10000000L

Represents the number of ticks in 1 second.

Definition at line 22 of file TimeSpan.cs.

◆ Zero

readonly TimeSpan System.TimeSpan.Zero = new TimeSpan(0L)
static

Represents the zero T:System.TimeSpan value. This field is read-only.

Definition at line 64 of file TimeSpan.cs.

Property Documentation

◆ Days

int System.TimeSpan.Days
get

Gets the days component of the time interval represented by the current T:System.TimeSpan structure.

Returns
The day component of this instance. The return value can be positive or negative.

Definition at line 96 of file TimeSpan.cs.

◆ Hours

int System.TimeSpan.Hours
get

Gets the hours component of the time interval represented by the current T:System.TimeSpan structure.

Returns
The hour component of the current T:System.TimeSpan structure. The return value ranges from -23 through 23.

Definition at line 108 of file TimeSpan.cs.

◆ Milliseconds

int System.TimeSpan.Milliseconds
get

Gets the milliseconds component of the time interval represented by the current T:System.TimeSpan structure.

Returns
The millisecond component of the current T:System.TimeSpan structure. The return value ranges from -999 through 999.

Definition at line 120 of file TimeSpan.cs.

◆ Minutes

int System.TimeSpan.Minutes
get

Gets the minutes component of the time interval represented by the current T:System.TimeSpan structure.

Returns
The minute component of the current T:System.TimeSpan structure. The return value ranges from -59 through 59.

Definition at line 132 of file TimeSpan.cs.

◆ Seconds

int System.TimeSpan.Seconds
get

Gets the seconds component of the time interval represented by the current T:System.TimeSpan structure.

Returns
The second component of the current T:System.TimeSpan structure. The return value ranges from -59 through 59.

Definition at line 144 of file TimeSpan.cs.

◆ Ticks

long System.TimeSpan.Ticks
get

Gets the number of ticks that represent the value of the current T:System.TimeSpan structure.

Returns
The number of ticks contained in this instance.

Definition at line 84 of file TimeSpan.cs.

◆ TotalDays

double System.TimeSpan.TotalDays
get

Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional days.

Returns
The total number of days represented by this instance.

Definition at line 156 of file TimeSpan.cs.

◆ TotalHours

double System.TimeSpan.TotalHours
get

Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional hours.

Returns
The total number of hours represented by this instance.

Definition at line 168 of file TimeSpan.cs.

◆ TotalMilliseconds

double System.TimeSpan.TotalMilliseconds
get

Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional milliseconds.

Returns
The total number of milliseconds represented by this instance.

Definition at line 180 of file TimeSpan.cs.

◆ TotalMinutes

double System.TimeSpan.TotalMinutes
get

Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional minutes.

Returns
The total number of minutes represented by this instance.

Definition at line 201 of file TimeSpan.cs.

◆ TotalSeconds

double System.TimeSpan.TotalSeconds
get

Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional seconds.

Returns
The total number of seconds represented by this instance.

Definition at line 213 of file TimeSpan.cs.


The documentation for this struct was generated from the following file: