public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>
Object
ValueType
TimeSpanThis type implements IComparable, System.IComparable<System.TimeSpan>, and System.IEquatable<System.TimeSpan>.
mscorlib
BCL
Represents an interval of time.
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.
]
System Namespace
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
public TimeSpan(long ticks);
Constructs and initializes a new TimeSpan with the specified number of ticks.
- ticks
- A Int64 that specifies the number of ticks with which to initialize the new TimeSpan .
System.TimeSpan Structure, System Namespace
public TimeSpan(int hours, int minutes, int seconds);
Constructs and initializes a new TimeSpan with the specified numbers of hours, minutes, and seconds.
- 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.
Exception Type Condition ArgumentOutOfRangeException The parameters specify a TimeSpan value less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.
The specified hours, minutes, and seconds are converted to ticks, and that value is used to initialize the new TimeSpan.
System.TimeSpan Structure, System Namespace
public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);
Constructs and initializes a new TimeSpan with the specified numbers of days, hours, minutes, seconds, and milliseconds.
- 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.
Exception Type Condition ArgumentOutOfRangeException The parameters specify a TimeSpan value less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.
The specified days, hours, minutes, seconds, and milliseconds are converted to ticks, and that value is used to initialize the new TimeSpan.
System.TimeSpan Structure, System Namespace
public TimeSpan(int days, int hours, int minutes, int seconds);
Constructs and initializes a new TimeSpan with the specified numbers of days, hours, minutes, and seconds.
- 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.
Exception Type Condition ArgumentOutOfRangeException The parameters specify a TimeSpan value less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.
The specified days, hours, minutes, and seconds are converted to ticks, and that value is used to initialize the new TimeSpan.
System.TimeSpan Structure, System Namespace
public TimeSpan Add(TimeSpan ts);
Adds the specified TimeSpan to the current instance.
- ts
- A TimeSpan instance to add to the current instance.
A TimeSpan that represents the value of the current instance plus the value of ts.
Exception Type Condition OverflowException The 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.
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
System.TimeSpan Structure, System Namespace
public static int Compare(TimeSpan t1, TimeSpan t2);
Returns the sort order of two TimeSpan structures.
- t1
- The first TimeSpan to compare.
- t2
- The second TimeSpan to compare.
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:
Value Condition Any negative number t1 < t2. Zero t1 == t2. Any positive number t1 > t2.
System.TimeSpan Structure, System Namespace
public int CompareTo(object value);
Returns the sort order of the current instance compared to the specified Object.
- value
- The Object to compare to the current instance.
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:
Value Condition Any negative number Current instance < value. Zero Current instance == value. Any positive number Current instance > value, or value is a null reference.
Exception Type Condition ArgumentException value is not a TimeSpan and is not a null reference.
[Note: This method is implemented to support the IComparable interface.]
System.TimeSpan Structure, System Namespace
public int CompareTo(TimeSpan value);
Returns the sort order of the current instance compared to the specified TimeSpan.
- value
- The TimeSpan to compare to the current instance.
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:
Value Condition Any negative number Current instance < value. Zero Current instance == value. Any positive number Current instance > value.
[Note: This method is implemented to support the System.IComparable<System.TimeSpan> interface.]
System.TimeSpan Structure, System Namespace
public TimeSpan Duration();
Returns a TimeSpan whose value is the absolute value of the current instance.
A TimeSpan whose value is the absolute value of the current instance.
Exception Type Condition OverflowException The value of the current instance is System.TimeSpan.MinValue.
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
System.TimeSpan Structure, System Namespace
public static bool Equals(TimeSpan t1, TimeSpan t2);
Determines whether two TimeSpan structures represent the same type and value.
- t1
- The first instance of TimeSpan to compare for equality.
- t2
- The second instance of TimeSpan to compare for equality.
true
if t1 and t2 represent the same value; otherwise,false
.
System.TimeSpan Structure, System Namespace
public override bool Equals(object value);
Determines whether the current instance and the specified Object represent the same type and value.
- value
- The Object to compare to the current instance.
true
if value represents the same type and value as the current instance. If value is a null reference or is not a TimeSpan, returnsfalse
.
[Note: This method overrides System.Object.Equals(System.Object).]
System.TimeSpan Structure, System Namespace
public override bool Equals(TimeSpan obj);
Determines whether the current instance and the specified TimeSpan represent the same value.
- value
- The TimeSpan to compare to the current instance.
true
if value represents the same value as the current instance; otherwise,false
.
[Note: This method is implemented to support the System.IEquatable<System.TimeSpan> interface.]
System.TimeSpan Structure, System Namespace
public static TimeSpan FromDays(double value);
Returns a TimeSpan that represents the specified number of days where the specification is accurate to the nearest millisecond.
- value
- A Double that specifies the number of days with which the new TimeSpan is initialized.
A TimeSpan that represents value.
Exception Type Condition OverflowException The TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue. ArgumentException value is equal to System.Double.NaN.
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.
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public static TimeSpan FromHours(double value);
Returns a TimeSpan that represents the specified number of hours where the specification is accurate to the nearest millisecond.
- value
- A Double that specifies the number of hours with which the new TimeSpan is initialized.
A TimeSpan that represents value.
Exception Type Condition OverflowException The TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue. ArgumentException value is equal to System.Double.NaN.
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.
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public static TimeSpan FromMilliseconds(double value);
Returns a TimeSpan that represents the specified number of milliseconds where the specification is accurate to the nearest millisecond.
- value
- A Double that specifies the number of milliseconds with which the new TimeSpan is initialized.
A TimeSpan that represents value.
Exception Type Condition OverflowException The TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue. ArgumentException value is equal to System.Double.NaN.
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.
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public static TimeSpan FromMinutes(double value);
Returns a TimeSpan that represents the specified number of minutes where the specification is accurate to the nearest millisecond.
- value
- A Double that specifies the number of minutes with which the new TimeSpan is initialized.
A TimeSpan that represents value.
Exception Type Condition OverflowException The TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue. ArgumentException value is equal to System.Double.NaN.
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.
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public static TimeSpan FromSeconds(double value);
Returns a TimeSpan that represents the specified number of seconds where the specification is accurate to the nearest millisecond.
- value
- A Double that specifies the number of seconds with which the new TimeSpan is initialized.
A TimeSpan that represents value.
Exception Type Condition OverflowException The TimeSpan represented by value is greater than System.TimeSpan.MaxValue or less than System.TimeSpan.MinValue. ArgumentException value is equal to System.Double.NaN.
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.
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public static TimeSpan FromTicks(long value);
Returns a TimeSpan that represents the specified number of ticks.
- value
- A Int64 that specifies the number of ticks with which the new TimeSpan is initialized.
A TimeSpan with a value of value.
This method is equivalent to the TimeSpan(Int64) constructor.
System.TimeSpan Structure, System Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 value containing a hash code for the current instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.]
System.TimeSpan Structure, System Namespace
public TimeSpan Negate();
Returns a TimeSpan with the same absolute value but opposite sign as the current instance.
A TimeSpan with the same absolute value but with the opposite sign as the current instance.
Exception Type Condition OverflowException The value of the current instance is System.TimeSpan.MinValue.
System.TimeSpan Structure, System Namespace
public static TimeSpan Parse(string s);
Returns the specified String converted to a TimeSpan value.
- 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.
The TimeSpan value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is in an invalid format. OverflowException s 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.
The symbols used in the parameter description for s are as follows:
Item Description ws White 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.
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
System.TimeSpan Structure, System Namespace
public TimeSpan Subtract(TimeSpan ts);
Subtracts the value of the specified TimeSpan from the value of the current instance.
- ts
- A TimeSpan whose value to subtract from the value of the current instance.
A TimeSpan whose value is equal to the value of the current instance minus the value of ts.
Exception Type Condition OverflowException The difference between the value of the current instance and ts is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.
System.TimeSpan Structure, System Namespace
public override string ToString();
Returns a String representation of the value of the current instance.
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.
Component Description "-" 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.
[Note: This method overrides System.Object.ToString.]
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
System.TimeSpan Structure, System Namespace
public static TimeSpan operator +(TimeSpan t1, TimeSpan t2);
Adds the values of two TimeSpan instances.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
A TimeSpan whose value is the sum of the values of t1 and t2.
Exception Type Condition OverflowException The sum of t1 and t2 is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.
System.TimeSpan Structure, System Namespace
public static bool operator ==(TimeSpan t1, TimeSpan t2);
Determines whether the value of one TimeSpan is equal to the value of another TimeSpan.
- t1
- The first TimeSpan
- t2
- The second TimeSpan
true
if the values of t1 and t2 are equal; otherwise,false
.
System.TimeSpan Structure, System Namespace
public static bool operator >(TimeSpan t1, TimeSpan t2);
Determines whether the value one TimeSpan is greater than the value of another TimeSpan.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
true
if the value of t1 is greater than the value of t2; otherwise,false
.
System.TimeSpan Structure, System Namespace
public static bool operator >=(TimeSpan t1, TimeSpan t2);
Determines whether the value of one TimeSpan is greater than or equal to the value of another TimeSpan.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
true
if the value of t1 is greater than or equal to the value of t2; otherwise,false
.
System.TimeSpan Structure, System Namespace
public static bool operator !=(TimeSpan t1, TimeSpan t2);
Determines whether the value of one TimeSpan is unequal to the value of another TimeSpan.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
true
if the values of t1 and t2 are unequal; otherwise,false
.
System.TimeSpan Structure, System Namespace
public static bool operator <(TimeSpan t1, TimeSpan t2);
Determines whether the value of one TimeSpan is less than the value of another TimeSpan.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
true
if the value of t1 is less than the value of t2; otherwise,false
.
System.TimeSpan Structure, System Namespace
public static bool operator <=(TimeSpan t1, TimeSpan t2);
Determines whether the value of one TimeSpan is less than or equal to the value of another TimeSpan.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
true
if the value of t1 is less than or equal to the value of t2; otherwise,false
.
System.TimeSpan Structure, System Namespace
public static TimeSpan operator -(TimeSpan t1, TimeSpan t2);
Subtracts the value of one TimeSpan from the value of another TimeSpan.
- t1
- The first TimeSpan.
- t2
- The second TimeSpan.
A TimeSpan whose value is the result of the value of t1 minus the value of t2.
Exception Type Condition OverflowException The value of t2 subtracted from t1 is less than System.TimeSpan.MinValue or greater than System.TimeSpan.MaxValue.
System.TimeSpan Structure, System Namespace
public static TimeSpan operator -(TimeSpan t);
Returns a TimeSpan whose value is the negated value of a specified TimeSpan.
- t
- A TimeSpan whose value will be negated.
A TimeSpan with the same absolute value but the opposite sign as t.
Exception Type Condition OverflowException t equals System.TimeSpan.MinValue.
System.TimeSpan Structure, System Namespace
public static TimeSpan operator +(TimeSpan t);
Returns the specified instance of TimeSpan.
- t
- A TimeSpan.
TimeSpant.
This method returns TimeSpant.
System.TimeSpan Structure, System Namespace
public static readonly TimeSpan MaxValue;
Returns a TimeSpan whose value is the maximum value for the TimeSpan type.
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.
System.TimeSpan Structure, System Namespace
public static readonly TimeSpan MinValue;
Returns a TimeSpan whose value is the minimum value for the TimeSpan type.
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.
System.TimeSpan Structure, System Namespace
public const long TicksPerDay = 864000000000;
Represents the number of ticks in 1 day.
The value of this constant is 864 billion (8.64x1011 ).
System.TimeSpan Structure, System Namespace
public const long TicksPerHour = 36000000000;
Represents the number of ticks in 1 hour.
The value of this constant is 36 billion (3.6x1010 ).
System.TimeSpan Structure, System Namespace
public const long TicksPerMillisecond = 10000;
Represents the number of ticks in 1 millisecond.
The value of this constant is 10 thousand (104 ).
System.TimeSpan Structure, System Namespace
public const long TicksPerMinute = 600000000;
Represents the number of ticks in 1 minute.
The value of this constant is 600 million (6x108 ).
System.TimeSpan Structure, System Namespace
public const long TicksPerSecond = 10000000;
Represents the number of ticks in 1 second.
The value of this constant is 10 million (107 ).
System.TimeSpan Structure, System Namespace
public static readonly TimeSpan Zero;
Returns a TimeSpan whose value is 0.
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.]
System.TimeSpan Structure, System Namespace
public int Days { get; }
Gets the number days represented by the current instance.
A Int32 represents the days component of the current instance. [Note: See System.TimeSpan.ToString for a more detailed description of the days component.]
This property is read-only.
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
System.TimeSpan Structure, System Namespace
public int Hours { get; }
Gets the number of hours represented by the current instance.
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.]
This property is read-only.
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
System.TimeSpan Structure, System Namespace
public int Milliseconds { get; }
Gets the number of milliseconds represented by the current instance.
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.]
This property is read-only.
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
System.TimeSpan Structure, System Namespace
public int Minutes { get; }
Gets the number of minutes represented by the current instance.
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.]
This property is read-only.
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
System.TimeSpan Structure, System Namespace
public int Seconds { get; }
Gets the number of seconds represented by the current instance.
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.]
This property is read-only.
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
System.TimeSpan Structure, System Namespace
public long Ticks { get; }
Gets the number of ticks represented by the current instance.
A Int64 specifying the number of ticks represented by the current instance.
This property is read-only.
System.TimeSpan Structure, System Namespace
public double TotalDays { get; }
Gets the value of the current instance expressed in days.
A Double that specifies the total number of days represented by the current instance.
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.]
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
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public double TotalHours { get; }
Gets the value of the current instance expressed in hours.
A Double that specifies the total number of hours represented by the current instance.
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.]
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
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public double TotalMilliseconds { get; }
Gets the value of the current instance expressed in milliseconds.
A Double that specifies the total number of milliseconds represented by the current instance.
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.]
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
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public double TotalMinutes { get; }
Gets the value of the current instance expressed in minutes.
A Double that specifies the total number of minutes represented by the current instance.
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.]
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
ExtendedNumerics
System.TimeSpan Structure, System Namespace
public double TotalSeconds { get; }
Gets the value of the current instance expressed in seconds.
A Double that specifies the total number of seconds represented by the current instance.
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.]
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
ExtendedNumerics
System.TimeSpan Structure, System Namespace