|
|
System.TimeSpan Structure |
|
|
Description | |
|
The TimeSpan holds a time span in days, hours, minutes, seconds and milliseconds. Unlike DateTime, which is a point in time, TimeSpan is an elapsed period of time. For example, two and a half hours.
Internally, the elapsed time is in terms of a number of elemental ticks (0.0000001 seconds).
It can be used in arithmetic on DateTime values, for example, by adding a TimeSpan value to a point in time, or as the result of the difference between two dates. |
|
Syntax | | | Constructor Create ( | Ticks : Long
; ); | Constructor Create ( | Hours : Integer; Minutes : Integer; Seconds : Integer
); | Constructor Create ( | Days : Integer; Hours : Integer; Minutes : Integer; Seconds : Integer
); | Constructor Create ( | Days : Integer; Hours : Integer; Minutes : Integer; Seconds : Integer; Milliseconds : Integer ); |
| Methods | | | | Add | Adds a timespan to the current timespan | | Compare | Compares twoTimeSpan values | | CompareTo | Compares the current TimeSpan value to another | | Duration | Returns the absolute value of the current TimeSpan | | Equals | Returns true if TimeSpan values are exactly the same | | FromDays | Creates a TimeSpan value from a given number of days | | FromHours | Creates a TimeSpan value from a given number of hours | | FromMilliseconds | Creates a TimeSpan value from a given number of milliseconds | | FromMinutes | Creates a TimeSpan value from a given number of minutes | | FromSeconds | Creates a TimeSpan value from a given number of seconds | | FromTicks | Creates a TimeSpan value from a given number of ticks | | Negate | Negates the current TimeSpan value | | Parse | Converts a string representation of time span into a TimeSpan value | | Subtract | Subtracts a TimeSpan from the current TimeSpan | | ToString | Converts a TimeSpan value into a string |
|
|
| Fields | | | MinValue | | Int64 | | Minimum number of ticks : -9,223,372,036,854,775,808
| MaxValue | | Int64 | | Maximum number of ticks : 9,223,372,036,854,775,807
| TicksPerDay | | Int64 | | Constant number of ticks in a day : 864,000,000,000
| TicksPerHour | | Int64 | | Constant number of ticks in an hour : 36,000,000,000
| TicksPerMinute | | Int64 | | Constant number of ticks in a minute : 600,000,000
| TicksPerSecond | | Int64 | | Constant number of ticks in a second : 10,000,000
| TicksPerMillisecond | | Int64 | | Constant number of ticks in a millisecond : 10,000
| Zero | | TimeSpan | | 0 value time span : 0 ticks
|
| Properties | | | Days | | Integer | | Days component
| Hours | | Integer | | Hours component
| Minutes | | Integer | | Minutes component
| Seconds | | Integer | | Seconds component
| Milliseconds | | Integer | | Milliseconds component
| Ticks | | Int64 | | Ticks component
| TotalDays | | Double | | Timespan expressed as days and part days
| TotalHours | | Double | | Timespan expressed as hours and part hours
| TotalMinutes | | Double | | Timespan expressed as minutes and part minutes
| TotalSeconds | | Double | | Timespan expressed as seconds and part seconds
| TotalMilliseconds | | Double | | Timespan expressed as milliseconds and part milliseconds |
| Operators | | | + | Adds a specified time interval to a specified date and time or time span.
| = | Determines whether two specified instances of TimeSpan are equal.
| > | Determines whether one specified TimeSpan is greater than another specified TimeSpan.
| >= | Determines whether one specified TimeSpan is greater than or equal to another specified TimeSpan.
| <> | Determines whether two specified instances of TimeSpan are not equal.
| < | Determines whether one specified TimeSpan is less than another specified TimeSpan.
| <= | Determines whether one specified TimeSpan is less than or equal to another specified TimeSpan.
| - | Subtracts a specified TimeSpan from a specified TimeSpan or DateTime. Also negates a TimeSpan value (unary operator). |
|
Microsoft MSDN links | |
|
|
|
|
|
|
|
|