System.TimeSpan Structure

public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>

Base Types

Object
  ValueType
    TimeSpan

This type implements IComparable, System.IComparable<System.TimeSpan>, and System.IEquatable<System.TimeSpan>.

Assembly

mscorlib

Library

BCL

Summary

Represents an interval of time.

Description

The TimeSpan structure represents an interval of time with values ranging from System.Int64.MinValue to System.Int64.MaxValue 100-nanosecond ticks.

[Note: The value of a TimeSpan is represented internally as a number of 100-nanosecond ticks. Both the specification of a number of ticks and the value of a TimeSpan can be positive or negative.

A TimeSpan can be represented as a string in the format "[-]d.hh:mm:ss.ff" where "-" is an optional sign for negative TimeSpan values, the "d" component is days, "hh" is hours, "mm" is minutes, "ss" is seconds, and "ff" is fractions of a second. For example, a TimeSpan initialized with 1013 ticks would be represented as "11.13:46:40", which is 11 days, 13 hours, 46 minutes, and 40 seconds.

Due to a varying number of days in months and years, the longest unit of time that is used by this structure is the day.

]

See Also

System Namespace

Members

TimeSpan Constructors

TimeSpan(long) Constructor
TimeSpan(int, int, int) Constructor
TimeSpan(int, int, int, int, int) Constructor
TimeSpan(int, int, int, int) Constructor

TimeSpan Methods

TimeSpan.Add Method
TimeSpan.Compare Method
TimeSpan.CompareTo(System.Object) Method
TimeSpan.CompareTo(System.TimeSpan) Method
TimeSpan.Duration Method
TimeSpan.Equals(System.TimeSpan, System.TimeSpan) Method
TimeSpan.Equals(System.Object) Method
TimeSpan.Equals(System.TimeSpan) Method
TimeSpan.FromDays Method
TimeSpan.FromHours Method
TimeSpan.FromMilliseconds Method
TimeSpan.FromMinutes Method
TimeSpan.FromSeconds Method
TimeSpan.FromTicks Method
TimeSpan.GetHashCode Method
TimeSpan.Negate Method
TimeSpan.Parse Method
TimeSpan.Subtract Method
TimeSpan.ToString Method
TimeSpan.op_Addition Method
TimeSpan.op_Equality Method
TimeSpan.op_GreaterThan Method
TimeSpan.op_GreaterThanOrEqual Method
TimeSpan.op_Inequality Method
TimeSpan.op_LessThan Method
TimeSpan.op_LessThanOrEqual Method
TimeSpan.op_Subtraction Method
TimeSpan.op_UnaryNegation Method
TimeSpan.op_UnaryPlus Method

TimeSpan Fields

TimeSpan.MaxValue Field
TimeSpan.MinValue Field
TimeSpan.TicksPerDay Field
TimeSpan.TicksPerHour Field
TimeSpan.TicksPerMillisecond Field
TimeSpan.TicksPerMinute Field
TimeSpan.TicksPerSecond Field
TimeSpan.Zero Field

TimeSpan Properties

TimeSpan.Days Property
TimeSpan.Hours Property
TimeSpan.Milliseconds Property
TimeSpan.Minutes Property
TimeSpan.Seconds Property
TimeSpan.Ticks Property
TimeSpan.TotalDays Property
TimeSpan.TotalHours Property
TimeSpan.TotalMilliseconds Property
TimeSpan.TotalMinutes Property
TimeSpan.TotalSeconds Property


TimeSpan(long) Constructor

public TimeSpan(long ticks);

Summary

Constructs and initializes a new TimeSpan with the specified number of ticks.

Parameters

ticks
A Int64 that specifies the number of ticks with which to initialize the new TimeSpan .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan(int, int, int) Constructor

public TimeSpan(int hours, int minutes, int seconds);

Summary

Constructs and initializes a new TimeSpan with the specified numbers of hours, minutes, and seconds.

Parameters

hours
A Int32 that specifies the number of hours with which to initialize the new TimeSpan.
minutes
A Int32 that specifies the number of minutes with which to initialize the new TimeSpan.
seconds
A Int32 that specifies the number of seconds with which to initialize the new TimeSpan.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe parameters specify a TimeSpan value less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

Description

The specified hours, minutes, and seconds are converted to ticks, and that value is used to initialize the new TimeSpan.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan(int, int, int, int, int) Constructor

public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);

Summary

Constructs and initializes a new TimeSpan with the specified numbers of days, hours, minutes, seconds, and milliseconds.

Parameters

days
A Int32 that specifies the number of days with which to initialize the new TimeSpan.
hours
A Int32 that specifies the number of hours with which to initialize the new TimeSpan.
minutes
A Int32 that specifies the number of minutes with which to initialize the new TimeSpan.
seconds
A Int32 that specifies the number of seconds with which to initialize the new TimeSpan.
milliseconds
A Int32 that specifies the number of milliseconds with which to initialize the new TimeSpan.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe parameters specify a TimeSpan value less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

Description

The specified days, hours, minutes, seconds, and milliseconds are converted to ticks, and that value is used to initialize the new TimeSpan.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan(int, int, int, int) Constructor

public TimeSpan(int days, int hours, int minutes, int seconds);

Summary

Constructs and initializes a new TimeSpan with the specified numbers of days, hours, minutes, and seconds.

Parameters

days
A Int32 that specifies the number of days with which to initialize the new TimeSpan.
hours
A Int32 that specifies the number of hours with which to initialize the new TimeSpan.
minutes
A Int32 that specifies the number of minutes with which to initialize the new TimeSpan.
seconds
A Int32 that specifies the number of seconds with which to initialize the new TimeSpan.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe parameters specify a TimeSpan value less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

Description

The specified days, hours, minutes, and seconds are converted to ticks, and that value is used to initialize the new TimeSpan.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Add Method

public TimeSpan Add(TimeSpan ts);

Summary

Adds the specified TimeSpan to the current instance.

Parameters

ts
A TimeSpan instance to add to the current instance.

Return Value

A TimeSpan that represents the value of the current instance plus the value of ts.

Exceptions

Exception TypeCondition
OverflowExceptionThe sum of the value of the current instance and the value of ts is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

Example

This example demonstrates the System.TimeSpan.Add(System.TimeSpan) method.

using System;
public class TimeSpanAddExample {
   public static void Main() {
      TimeSpan ts = new TimeSpan(Int32.MaxValue);
      Console.WriteLine("The value of the timespan 'ts' is {0}", ts);
      Console.WriteLine("ts.Add(ts) = {0}", ts.Add(ts));
   }
}
The output is

The value of the timespan 'ts' is 00:03:34.7483647

ts.Add(ts) = 00:07:09.4967294

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Compare Method

public static int Compare(TimeSpan t1, TimeSpan t2);

Summary

Returns the sort order of two TimeSpan structures.

Parameters

t1
The first TimeSpan to compare.
t2
The second TimeSpan to compare.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of t1 as compared to t2. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

ValueCondition
Any negative numbert1 < t2.
Zerot1 == t2.
Any positive numbert1 > t2.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.CompareTo(System.Object) Method

public int CompareTo(object value);

Summary

Returns the sort order of the current instance compared to the specified Object.

Parameters

value
The Object to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

ValueCondition
Any negative numberCurrent instance < value.
ZeroCurrent instance == value.
Any positive numberCurrent instance > value, or value is a null reference.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is not a TimeSpan and is not a null reference.

Description

[Note: This method is implemented to support the IComparable interface.]

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.CompareTo(System.TimeSpan) Method

public int CompareTo(TimeSpan value);

Summary

Returns the sort order of the current instance compared to the specified TimeSpan.

Parameters

value
The TimeSpan to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

ValueCondition
Any negative numberCurrent instance < value.
ZeroCurrent instance == value.
Any positive numberCurrent instance > value.

Description

[Note: This method is implemented to support the System.IComparable<System.TimeSpan> interface.]

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Duration Method

public TimeSpan Duration();

Summary

Returns a TimeSpan whose value is the absolute value of the current instance.

Return Value

A TimeSpan whose value is the absolute value of the current instance.

Exceptions

Exception TypeCondition
OverflowExceptionThe value of the current instance is System.TimeSpan.MinValue.

Example

The following example demonstrates the System.TimeSpan.Duration method.

using System;
public class TimeSpanDurationExample {
   public static void Main() {
      TimeSpan ts = new TimeSpan(Int32.MinValue);
      Console.Write("The absolute value of TimeSpan {0} ", ts);
      Console.WriteLine("is {0}", ts.Duration());
   }
}
The output is

The absolute value of TimeSpan -00:03:34.7483648 is 00:03:34.7483648

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Equals(System.TimeSpan, System.TimeSpan) Method

public static bool Equals(TimeSpan t1, TimeSpan t2);

Summary

Determines whether two TimeSpan structures represent the same type and value.

Parameters

t1
The first instance of TimeSpan to compare for equality.
t2
The second instance of TimeSpan to compare for equality.

Return Value

true if t1 and t2 represent the same value; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Equals(System.Object) Method

public override bool Equals(object value);

Summary

Determines whether the current instance and the specified Object represent the same type and value.

Parameters

value
The Object to compare to the current instance.

Return Value

true if value represents the same type and value as the current instance. If value is a null reference or is not a TimeSpan, returns false .

Description

[Note: This method overrides System.Object.Equals(System.Object).]

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Equals(System.TimeSpan) Method

public override bool Equals(TimeSpan obj);

Summary

Determines whether the current instance and the specified TimeSpan represent the same value.

Parameters

value
The TimeSpan to compare to the current instance.

Return Value

true if value represents the same value as the current instance; otherwise, false .

Description

[Note: This method is implemented to support the System.IEquatable<System.TimeSpan> interface.]

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.FromDays Method

public static TimeSpan FromDays(double value);

Summary

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

Parameters

value
A Double that specifies the number of days with which the new TimeSpan is initialized.

Return Value

A TimeSpan that represents value.

Exceptions

Exception TypeCondition
OverflowExceptionThe TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue.
ArgumentExceptionvalue is equal to System.Double.NaN.

Description

value will only be considered accurate to the nearest millisecond.

If value is System.Double.PositiveInfinity, a TimeSpan with the value System.TimeSpan.MaxValue is returned. If value is System.Double.NegativeInfinity, a TimeSpan with the value System.TimeSpan.MinValue is returned.

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.FromHours Method

public static TimeSpan FromHours(double value);

Summary

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

Parameters

value
A Double that specifies the number of hours with which the new TimeSpan is initialized.

Return Value

A TimeSpan that represents value.

Exceptions

Exception TypeCondition
OverflowExceptionThe TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue.
ArgumentExceptionvalue is equal to System.Double.NaN.

Description

value will only be considered accurate to the nearest millisecond.

If value is System.Double.PositiveInfinity, a TimeSpan with the value System.TimeSpan.MaxValue is returned. If value is System.Double.NegativeInfinity, a TimeSpan with the value System.TimeSpan.MinValue is returned.

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.FromMilliseconds Method

public static TimeSpan FromMilliseconds(double value);

Summary

Returns a TimeSpan that represents the specified number of milliseconds where the specification is accurate to the nearest millisecond.

Parameters

value
A Double that specifies the number of milliseconds with which the new TimeSpan is initialized.

Return Value

A TimeSpan that represents value.

Exceptions

Exception TypeCondition
OverflowExceptionThe TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue.
ArgumentExceptionvalue is equal to System.Double.NaN.

Description

value will only be considered accurate to the nearest millisecond.

If value is System.Double.PositiveInfinity, a TimeSpan with the value System.TimeSpan.MaxValue is returned. If value is System.Double.NegativeInfinity, a TimeSpan with the value System.TimeSpan.MinValue is returned.

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.FromMinutes Method

public static TimeSpan FromMinutes(double value);

Summary

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

Parameters

value
A Double that specifies the number of minutes with which the new TimeSpan is initialized.

Return Value

A TimeSpan that represents value.

Exceptions

Exception TypeCondition
OverflowExceptionThe TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue.
ArgumentExceptionvalue is equal to System.Double.NaN.

Description

value will only be considered accurate to the nearest millisecond.

If value is System.Double.PositiveInfinity, a TimeSpan with the value System.TimeSpan.MaxValue is returned. If value is System.Double.NegativeInfinity, a TimeSpan with the value System.TimeSpan.MinValue is returned.

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.FromSeconds Method

public static TimeSpan FromSeconds(double value);

Summary

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

Parameters

value
A Double that specifies the number of seconds with which the new TimeSpan is initialized.

Return Value

A TimeSpan that represents value.

Exceptions

Exception TypeCondition
OverflowExceptionThe TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue.
ArgumentExceptionvalue is equal to System.Double.NaN.

Description

value will only be considered accurate to the nearest millisecond.

If value is System.Double.PositiveInfinity, a TimeSpan with the value System.TimeSpan.MaxValue is returned. If value is System.Double.NegativeInfinity, a TimeSpan with the value System.TimeSpan.MinValue is returned.

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.FromTicks Method

public static TimeSpan FromTicks(long value);

Summary

Returns a TimeSpan that represents the specified number of ticks.

Parameters

value
A Int64 that specifies the number of ticks with which the new TimeSpan is initialized.

Return Value

A TimeSpan with a value of value.

Description

This method is equivalent to the TimeSpan(Int64) constructor.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 value containing a hash code for the current instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.]

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Negate Method

public TimeSpan Negate();

Summary

Returns a TimeSpan with the same absolute value but opposite sign as the current instance.

Return Value

A TimeSpan with the same absolute value but with the opposite sign as the current instance.

Exceptions

Exception TypeCondition
OverflowExceptionThe value of the current instance is System.TimeSpan.MinValue.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Parse Method

public static TimeSpan Parse(string s);

Summary

Returns the specified String converted to a TimeSpan value.

Parameters

s
A String containing the value to convert. s contains a time interval in the following form:

[ws][-][d.]hh:mm:ss[.ff][ws]

Items in square brackets ('[' and']') are optional. Colons and periods (':' and'.') are literal characters. For details on the remaining symbols, see the description section.

Return Value

The TimeSpan value obtained from s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is in an invalid format.
OverflowExceptions represents a number greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue.

-or-

At least one of the hours, minutes, or seconds components is outside its valid range.

Description

The symbols used in the parameter description for s are as follows:

ItemDescription
wsWhite space (zero or more space and/or tab characters).
"-"Minus sign, indicating a negative time interval.
"d"Days.
"hh"Hours, ranging from 0 to 23 inclusive.
"mm"Minutes, ranging from 0 to 59 inclusive.
"ss"Seconds, ranging from 0 to 59 inclusive.
"ff"Fractional seconds, from 1 to 7 decimal digits inclusive.

Example

This example demonstrates parsing a string to obtain a TimeSpan.

using System;
public class TimeSpanParseExample {
   public static void Main() {
      String str = "    -5.12:34:56.789     ";
      TimeSpan ts = TimeSpan.Parse(str);
      Console.WriteLine(@"The string ""{0}""", str); 
      Console.WriteLine("parses to TimeSpan {0}", ts);
   }
}
   
The output is

The string "    -5.12:34:56.789     "
parses to TimeSpan -5.12:34:56.7890000
 

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Subtract Method

public TimeSpan Subtract(TimeSpan ts);

Summary

Subtracts the value of the specified TimeSpan from the value of the current instance.

Parameters

ts
A TimeSpan whose value to subtract from the value of the current instance.

Return Value

A TimeSpan whose value is equal to the value of the current instance minus the value of ts.

Exceptions

Exception TypeCondition
OverflowExceptionThe difference between the value of the current instance and ts is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.ToString Method

public override string ToString();

Summary

Returns a String representation of the value of the current instance.

Return Value

A String representation of the current instance formatted as follows:

[-][d.]hh:mm:ss[.ff]

Items in square brackets ('[' and ']') are included provisionally: '-' is included if and only if the current instance is negative; "d." and ".ff" are included if and only if those components are non-zero. Colons and periods (':' and '.') are literal characters. Other components are as follows.

ComponentDescription
"-"Minus sign, indicating a negative time interval.
"d"Days.
"hh"Hours, ranging from 0 to 23 inclusive.
"mm"Minutes, ranging from 0 to 59 inclusive.
"ss"Seconds, ranging from 0 to 59 inclusive.
"ff"Fractional seconds.

Description

[Note: This method overrides System.Object.ToString.]

Example

This example demonstrates the System.TimeSpan.ToString method.

using System;
public class TimeSpanToStringExample {
   public static void Main() {
      TimeSpan tsOne = new TimeSpan(1, 23, 45, 54, 321);
      TimeSpan tsTwo = new TimeSpan(0, 23, 45, 54, 0);
      Console.Write("TimeSpan one, with d. and .ff: ");
      Console.WriteLine("{0}", tsOne.ToString());
      Console.Write("TimeSpan two, without d. and .ff: ");
      Console.WriteLine("{0}", tsTwo.ToString());
   }
}
The output is

TimeSpan one, with d. and .ff: 1.23:45:54.3210000

TimeSpan two, without d. and .ff: 23:45:54

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_Addition Method

public static TimeSpan operator +(TimeSpan t1, TimeSpan t2);

Summary

Adds the values of two TimeSpan instances.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

A TimeSpan whose value is the sum of the values of t1 and t2.

Exceptions

Exception TypeCondition
OverflowExceptionThe sum of t1 and t2 is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_Equality Method

public static bool operator ==(TimeSpan t1, TimeSpan t2);

Summary

Determines whether the value of one TimeSpan is equal to the value of another TimeSpan.

Parameters

t1
The first TimeSpan
t2
The second TimeSpan

Return Value

true if the values of t1 and t2 are equal; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_GreaterThan Method

public static bool operator >(TimeSpan t1, TimeSpan t2);

Summary

Determines whether the value one TimeSpan is greater than the value of another TimeSpan.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

true if the value of t1 is greater than the value of t2; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_GreaterThanOrEqual Method

public static bool operator >=(TimeSpan t1, TimeSpan t2);

Summary

Determines whether the value of one TimeSpan is greater than or equal to the value of another TimeSpan.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

true if the value of t1 is greater than or equal to the value of t2; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_Inequality Method

public static bool operator !=(TimeSpan t1, TimeSpan t2);

Summary

Determines whether the value of one TimeSpan is unequal to the value of another TimeSpan.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

true if the values of t1 and t2 are unequal; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_LessThan Method

public static bool operator  <(TimeSpan t1, TimeSpan t2);

Summary

Determines whether the value of one TimeSpan is less than the value of another TimeSpan.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

true if the value of t1 is less than the value of t2; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_LessThanOrEqual Method

public static bool operator <=(TimeSpan t1, TimeSpan t2);

Summary

Determines whether the value of one TimeSpan is less than or equal to the value of another TimeSpan.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

true if the value of t1 is less than or equal to the value of t2; otherwise, false .

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_Subtraction Method

public static TimeSpan operator -(TimeSpan t1, TimeSpan t2);

Summary

Subtracts the value of one TimeSpan from the value of another TimeSpan.

Parameters

t1
The first TimeSpan.
t2
The second TimeSpan.

Return Value

A TimeSpan whose value is the result of the value of t1 minus the value of t2.

Exceptions

Exception TypeCondition
OverflowExceptionThe value of t2 subtracted from t1 is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_UnaryNegation Method

public static TimeSpan operator -(TimeSpan t);

Summary

Returns a TimeSpan whose value is the negated value of a specified TimeSpan.

Parameters

t
A TimeSpan whose value will be negated.

Return Value

A TimeSpan with the same absolute value but the opposite sign as t.

Exceptions

Exception TypeCondition
OverflowExceptiont equals System.TimeSpan.MinValue.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.op_UnaryPlus Method

public static TimeSpan operator +(TimeSpan t);

Summary

Returns the specified instance of TimeSpan.

Parameters

t
A TimeSpan.

Return Value

TimeSpant.

Description

This method returns TimeSpant.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.MaxValue Field

public static readonly TimeSpan MaxValue;

Summary

Returns a TimeSpan whose value is the maximum value for the TimeSpan type.

Description

This field is read-only.

This field is a TimeSpan containing System.Int64.MaxValue ticks, the maximum TimeSpan value. The string representation of this value is positive 10675199.02:48:05.4775807.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.MinValue Field

public static readonly TimeSpan MinValue;

Summary

Returns a TimeSpan whose value is the minimum value for the TimeSpan type.

Description

This field is read-only.

This field is a TimeSpan containing System.Int64.MinValue ticks, the minimum TimeSpan value. The string representation of this value is negative 10675199.02:48:05.4775808.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TicksPerDay Field

public const long TicksPerDay = 864000000000;

Summary

Represents the number of ticks in 1 day.

Description

The value of this constant is 864 billion (8.64x1011 ).

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TicksPerHour Field

public const long TicksPerHour = 36000000000;

Summary

Represents the number of ticks in 1 hour.

Description

The value of this constant is 36 billion (3.6x1010 ).

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TicksPerMillisecond Field

public const long TicksPerMillisecond = 10000;

Summary

Represents the number of ticks in 1 millisecond.

Description

The value of this constant is 10 thousand (104 ).

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TicksPerMinute Field

public const long TicksPerMinute = 600000000;

Summary

Represents the number of ticks in 1 minute.

Description

The value of this constant is 600 million (6x108 ).

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TicksPerSecond Field

public const long TicksPerSecond = 10000000;

Summary

Represents the number of ticks in 1 second.

Description

The value of this constant is 10 million (107 ).

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Zero Field

public static readonly TimeSpan Zero;

Summary

Returns a TimeSpan whose value is 0.

Description

This field is read-only.

This field is a TimeSpan whose value is 0 ticks. [Note: This provides a convenient source for 0 in TimeSpan calculations.]

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Days Property

public int Days { get; }

Summary

Gets the number days represented by the current instance.

Property Value

A Int32 represents the days component of the current instance. [Note: See System.TimeSpan.ToString for a more detailed description of the days component.]

Description

This property is read-only.

Example

This example demonstrates using the System.TimeSpan.Days property.

using System;
public class TimeSpanPropertiesExampleOne {
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12+3456789);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("Days: {0}", ts.Days );
   }
}
The output is

11.13:46:40.3456789

Days: 11

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Hours Property

public int Hours { get; }

Summary

Gets the number of hours represented by the current instance.

Property Value

A Int32 between 0 and 23 inclusive, that represents the hours component of the current instance. [Note: See System.TimeSpan.ToString for a more detailed description of the hours component.]

Description

This property is read-only.

Example

This example demonstrates using the System.TimeSpan.Hours property.

using System;
public class TimeSpanPropertiesExampleOne {
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12+3456789);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("Hours: {0}", ts.Hours );
   }
}
The output is

11.13:46:40.3456789

Hours: 13

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Milliseconds Property

public int Milliseconds { get; }

Summary

Gets the number of milliseconds represented by the current instance.

Property Value

A Int32 between 0 and 999 inclusive, that represents the fractional seconds component of the current instance converted to milliseconds. [Note: See System.TimeSpan.ToString for a more detailed description of the fractional seconds component.]

Description

This property is read-only.

Example

This example demonstrates using the System.TimeSpan.Milliseconds property.

using System;
public class TimeSpanPropertiesExampleOne {
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12+3456789);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("Milliseconds: {0}", ts.Milliseconds );
   }
}
The output is

11.13:46:40.3456789

Milliseconds: 345

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Minutes Property

public int Minutes { get; }

Summary

Gets the number of minutes represented by the current instance.

Property Value

A Int32 between 0 and 59 inclusive, that represents the minutes component of the current instance. [Note: See System.TimeSpan.ToString for a more detailed description of the minutes component.]

Description

This property is read-only.

Example

This example demonstrates using the System.TimeSpan.Minutes property.

using System;
public class TimeSpanPropertiesExampleOne {
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12+3456789);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("Minutes: {0}", ts.Minutes );
   }
}
The output is

11.13:46:40.3456789

Minutes: 46

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Seconds Property

public int Seconds { get; }

Summary

Gets the number of seconds represented by the current instance.

Property Value

A Int32 between 0 and 59 inclusive, that represents the seconds component of the current instance. [Note: See System.TimeSpan.ToString for a more detailed description of the seconds component.]

Description

This property is read-only.

Example

This example demonstrates using the System.TimeSpan.Seconds property.

using System;
public class TimeSpanPropertiesExampleOne {
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12+3456789);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("Seconds: {0}", ts.Seconds );
   }
}
The output is

11.13:46:40.3456789

Seconds: 40

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.Ticks Property

public long Ticks { get; }

Summary

Gets the number of ticks represented by the current instance.

Property Value

A Int64 specifying the number of ticks represented by the current instance.

Description

This property is read-only.

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TotalDays Property

public double TotalDays { get; }

Summary

Gets the value of the current instance expressed in days.

Property Value

A Double that specifies the total number of days represented by the current instance.

Description

This property is read-only.

[Note: This property converts the value of the current instance from ticks to days. This number can include whole and fractional days.]

Example

This example demonstrates using the System.TimeSpan.TotalDays property.

using System;
public class TimeSpanTotalUnitsProperties{
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("TotalDays: {0}", ts.TotalDays);
   }
}
The output is

11.13:46:40

TotalDays: 11.5740740740741

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TotalHours Property

public double TotalHours { get; }

Summary

Gets the value of the current instance expressed in hours.

Property Value

A Double that specifies the total number of hours represented by the current instance.

Description

This property is read-only.

[Note: This property converts the value of the current instance from ticks to hours. This number can include whole and fractional hours.]

Example

This example demonstrates using the System.TimeSpan.TotalHours property.

using System;
public class TimeSpanTotalUnitsProperties{
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("TotalHours: {0}", ts.TotalHours);
   }
}
The output is

11.13:46:40

TotalHours: 277.777777777778

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TotalMilliseconds Property

public double TotalMilliseconds { get; }

Summary

Gets the value of the current instance expressed in milliseconds.

Property Value

A Double that specifies the total number of milliseconds represented by the current instance.

Description

This property is read-only.

[Note: This property converts the value of the current instance from ticks to milliseconds. This number can include whole and fractional milliseconds.]

Example

This example demonstrates using the System.TimeSpan.TotalMilliseconds property.

using System;
public class TimeSpanTotalUnitsProperties{
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("TotalMilliseconds: {0}", ts.TotalMilliseconds);
   }
}
The output is

11.13:46:40

TotalMilliseconds: 1000000000

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TotalMinutes Property

public double TotalMinutes { get; }

Summary

Gets the value of the current instance expressed in minutes.

Property Value

A Double that specifies the total number of minutes represented by the current instance.

Description

This property is read-only.

[Note: This property converts the value of the current instance from ticks to minutes. This number can include whole and fractional minutes.]

Example

This example demonstrates using the System.TimeSpan.TotalMinutes property.

using System;
public class TimeSpanTotalUnitsProperties{
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("TotalMinutes: {0}", ts.TotalMinutes);
   }
}
The output is

11.13:46:40

TotalMinutes: 16666.6666666667

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace

TimeSpan.TotalSeconds Property

public double TotalSeconds { get; }

Summary

Gets the value of the current instance expressed in seconds.

Property Value

A Double that specifies the total number of seconds represented by the current instance.

Description

This property is read-only.

[Note: This property converts the value of the current instance from ticks to seconds. This number can include whole and fractional seconds.]

Example

This example demonstrates using the System.TimeSpan.TotalSeconds property.

using System;
public class TimeSpanTotalUnitsProperties{
   public static void Main() {
      TimeSpan ts = new TimeSpan((Int64)10e12);
      Console.WriteLine(ts.ToString());
      Console.WriteLine("TotalSeconds: {0}", ts.TotalSeconds);
   }
}
The output is

11.13:46:40

TotalSeconds :1000000

Library

ExtendedNumerics

See Also

System.TimeSpan Structure, System Namespace