Share via


TimeSpan Structure

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents a time interval.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Structure TimeSpan
[SerializableAttribute]
public struct TimeSpan
[SerializableAttribute]
public value class TimeSpan
[<Sealed>]
[<SerializableAttribute>]
type TimeSpan =  struct end
JScript supports the use of structures, but not the declaration of new ones.

The TimeSpan type exposes the following members.

Constructors

  Name Description
Public method TimeSpan(Int64) Initializes a new TimeSpan to the specified number of ticks.
Public method TimeSpan(Int32, Int32, Int32) Initializes a new TimeSpan to a specified number of hours, minutes, and seconds.
Public method TimeSpan(Int32, Int32, Int32, Int32) Initializes a new TimeSpan to a specified number of days, hours, minutes, and seconds.
Public method TimeSpan(Int32, Int32, Int32, Int32, Int32) Initializes a new TimeSpan to a specified number of days, hours, minutes, seconds, and milliseconds.

Top

Properties

  Name Description
Public property Days Gets the days component of the time interval represented by the current TimeSpan structure.
Public property Hours Gets the hours component of the time interval represented by the current TimeSpan structure.
Public property Milliseconds Gets the milliseconds component of the time interval represented by the current TimeSpan structure.
Public property Minutes Gets the minutes component of the time interval represented by the current TimeSpan structure.
Public property Seconds Gets the seconds component of the time interval represented by the current TimeSpan structure.
Public property Ticks Gets the number of ticks that represent the value of the current TimeSpan structure.

Top

Methods

  Name Description
Public method Add Returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.
Public methodStatic member Compare 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.
Public method CompareTo 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 method Duration Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.
Public method Equals(Object) Returns a value indicating whether this instance is equal to a specified object. (Overrides ValueType. . :: . .Equals(Object).)
Public methodStatic member Equals(TimeSpan, TimeSpan) Returns a value that indicates whether two specified instances of TimeSpan are equal.
Public methodStatic member FromTicks Returns a TimeSpan that represents a specified time, where the specification is in units of ticks.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Negate Returns a new TimeSpan object whose value is the negated value of this instance.
Public method Subtract Returns a new TimeSpan object whose value is the difference between the specified TimeSpan object and this instance.
Public method ToString Converts the value of the current TimeSpan object to its equivalent string representation. (Overrides Object. . :: . .ToString() () () ().)

Top

Operators

  Name Description
Public operatorStatic member Addition Adds two specified TimeSpan instances.
Public operatorStatic member Equality Indicates whether two TimeSpan instances are equal.
Public operatorStatic member GreaterThan Indicates whether a specified TimeSpan is greater than another specified TimeSpan.
Public operatorStatic member GreaterThanOrEqual Indicates whether a specified TimeSpan is greater than or equal to another specified TimeSpan.
Public operatorStatic member Inequality Indicates whether two TimeSpan instances are not equal.
Public operatorStatic member LessThan Indicates whether a specified TimeSpan is less than another specified TimeSpan.
Public operatorStatic member LessThanOrEqual Indicates whether a specified TimeSpan is less than or equal to another specified TimeSpan.
Public operatorStatic member Subtraction Subtracts a specified TimeSpan from another specified TimeSpan.
Public operatorStatic member UnaryNegation Returns a TimeSpan whose value is the negated value of the specified instance.
Public operatorStatic member UnaryPlus Returns the specified instance of TimeSpan.

Top

Fields

  Name Description
Public fieldStatic member MaxValue Represents the maximum TimeSpan value. This field is read-only.
Public fieldStatic member MinValue Represents the minimum TimeSpan value. This field is read-only.
Public fieldStatic member TicksPerDay Represents the number of ticks in 1 day. This field is constant.
Public fieldStatic member TicksPerHour Represents the number of ticks in 1 hour. This field is constant.
Public fieldStatic member TicksPerMillisecond Represents the number of ticks in 1 millisecond. This field is constant.
Public fieldStatic member TicksPerMinute Represents the number of ticks in 1 minute. This field is constant.
Public fieldStatic member TicksPerSecond Represents the number of ticks in 1 second.
Public fieldStatic member Zero Represents the zero TimeSpan value. This field is read-only.

Top

Remarks

The value of a TimeSpan object is the number of ticks that equal the represented time interval. A tick is equal to 100 nanoseconds, or one ten-millionth of a second. The value of a TimeSpan object can range from TimeSpan..::..MinValue to TimeSpan..::..MaxValue.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System Namespace