Search Results for

    Show / Hide Table of Contents

    Struct TimeSpan

    Represents a time interval.

    Inherited Members
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: System
    Assembly: mscorlib.dll
    Syntax
    public struct TimeSpan
    Remarks

    A TimeSpan object represents a time interval (duration of time or elapsed time) that is measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The TimeSpan structure can also be used to represent the time of day, but only if the time is unrelated to a particular date. Otherwise, the DateTime structure should be used instead. 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 MinValue to MaxValue.

    Constructors

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

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

    Declaration
    public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
    Parameters
    Type Name Description
    int days

    Number of days.

    int hours

    Number of hours.

    int minutes

    Number of minutes.

    int seconds

    Number of seconds.

    int milliseconds

    Number of milliseconds.

    TimeSpan(int, int, int, int)

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

    Declaration
    public TimeSpan(int days, int hours, int minutes, int seconds)
    Parameters
    Type Name Description
    int days

    Number of days.

    int hours

    Number of hours.

    int minutes

    Number of minutes.

    int seconds

    Number of seconds.

    TimeSpan(int, int, int)

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

    Declaration
    public TimeSpan(int hours, int minutes, int seconds)
    Parameters
    Type Name Description
    int hours

    Number of hours.

    int minutes

    Number of minutes.

    int seconds

    Number of seconds.

    TimeSpan(long)

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

    Declaration
    public TimeSpan(long ticks)
    Parameters
    Type Name Description
    long ticks

    A time period expressed in 100-nanosecond units.

    Fields

    MaxValue

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

    Declaration
    public static readonly TimeSpan MaxValue
    Field Value
    Type Description
    TimeSpan

    MinValue

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

    Declaration
    public static readonly TimeSpan MinValue
    Field Value
    Type Description
    TimeSpan

    TicksPerDay

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

    Declaration
    public const long TicksPerDay = 864000000000
    Field Value
    Type Description
    long

    TicksPerHour

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

    Declaration
    public const long TicksPerHour = 36000000000
    Field Value
    Type Description
    long

    TicksPerMillisecond

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

    Declaration
    public const long TicksPerMillisecond = 10000
    Field Value
    Type Description
    long

    TicksPerMinute

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

    Declaration
    public const long TicksPerMinute = 600000000
    Field Value
    Type Description
    long

    TicksPerSecond

    Represents the number of ticks in 1 second.

    Declaration
    public const long TicksPerSecond = 10000000
    Field Value
    Type Description
    long

    Zero

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

    Declaration
    public static readonly TimeSpan Zero
    Field Value
    Type Description
    TimeSpan

    Properties

    Days

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

    Declaration
    public int Days { get; }
    Property Value
    Type Description
    int

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

    Hours

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

    Declaration
    public int Hours { get; }
    Property Value
    Type Description
    int

    The hour component of this instance. The return value ranges from -23 through 23.

    Milliseconds

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

    Declaration
    public int Milliseconds { get; }
    Property Value
    Type Description
    int

    The millisecond component of this instance. The return value ranges from -999 through 999.

    Minutes

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

    Declaration
    public int Minutes { get; }
    Property Value
    Type Description
    int

    The minute component of this instance. The return value ranges from -59 through 59.

    Seconds

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

    Declaration
    public int Seconds { get; }
    Property Value
    Type Description
    int

    The second component of this instance. The return value ranges from -59 through 59.

    Ticks

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

    Declaration
    public long Ticks { get; }
    Property Value
    Type Description
    long

    The number of ticks contained in this instance.

    TotalDays

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

    Declaration
    public double TotalDays { get; }
    Property Value
    Type Description
    double

    The total number of days represented by this instance.

    TotalHours

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

    Declaration
    public double TotalHours { get; }
    Property Value
    Type Description
    double

    The total number of hours represented by this instance.

    TotalMilliseconds

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

    Declaration
    public double TotalMilliseconds { get; }
    Property Value
    Type Description
    double

    The total number of milliseconds represented by this instance.

    TotalMinutes

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

    Declaration
    public double TotalMinutes { get; }
    Property Value
    Type Description
    double

    The total number of minutes represented by this instance.

    TotalSeconds

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

    Declaration
    public double TotalSeconds { get; }
    Property Value
    Type Description
    double

    The total number of seconds represented by this instance.

    Methods

    Add(TimeSpan)

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

    Declaration
    public TimeSpan Add(TimeSpan ts)
    Parameters
    Type Name Description
    TimeSpan ts

    The time interval to add.

    Returns
    Type Description
    TimeSpan

    A new object that represents the value of this instance plus the value of ts.

    Compare(TimeSpan, TimeSpan)

    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.

    Declaration
    public static int Compare(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    int

    One of the following values :

    -1 if t1 is shorter than t2.

    0 if t1 is equal to t2.

    1 if t1 is longer than t2.

    CompareTo(object)

    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.

    Declaration
    public int CompareTo(object value)
    Parameters
    Type Name Description
    object value

    An object to compare, or null.

    Returns
    Type Description
    int

    One of the following values :

    -1 if This instance is shorter than value.

    0 if This instance is equal to value.

    1 if This instance is longer than value or value is null.

    Duration()

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

    Declaration
    public TimeSpan Duration()
    Returns
    Type Description
    TimeSpan

    A new object whose value is the absolute value of the current TimeSpan object.

    Equals(object)

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

    Declaration
    public override bool Equals(object value)
    Parameters
    Type Name Description
    object value

    An object to compare with this instance.

    Returns
    Type Description
    bool

    true if value is a TimeSpan object that represents the same time interval as the current TimeSpan structure; otherwise, false.

    Overrides
    ValueType.Equals(object)

    Equals(TimeSpan, TimeSpan)

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

    Declaration
    public static bool Equals(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    FromDays(long)

    Returns a TimeSpan that represents a specified time, where the specification is in units of days.

    Declaration
    public static TimeSpan FromDays(long value)
    Parameters
    Type Name Description
    long value

    A number of days that represent a time.

    Returns
    Type Description
    TimeSpan

    An object that represents value.

    FromHours(long)

    Returns a TimeSpan that represents a specified time, where the specification is in units of hours.

    Declaration
    public static TimeSpan FromHours(long value)
    Parameters
    Type Name Description
    long value

    A number of hours that represent a time.

    Returns
    Type Description
    TimeSpan

    An object that represents value.

    FromMilliseconds(long)

    Returns a TimeSpan that represents a specified time, where the specification is in units of milliseconds.

    Declaration
    public static TimeSpan FromMilliseconds(long value)
    Parameters
    Type Name Description
    long value

    A number of milliseconds that represent a time.

    Returns
    Type Description
    TimeSpan

    An object that represents value.

    FromMinutes(long)

    Returns a TimeSpan that represents a specified time, where the specification is in units of minute.

    Declaration
    public static TimeSpan FromMinutes(long value)
    Parameters
    Type Name Description
    long value

    A number of minute that represent a time.

    Returns
    Type Description
    TimeSpan

    An object that represents value.

    FromSeconds(long)

    Returns a TimeSpan that represents a specified time, where the specification is in units of seconds.

    Declaration
    public static TimeSpan FromSeconds(long value)
    Parameters
    Type Name Description
    long value

    A number of seconds that represent a time.

    Returns
    Type Description
    TimeSpan

    An object that represents value.

    FromTicks(long)

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

    Declaration
    public static TimeSpan FromTicks(long value)
    Parameters
    Type Name Description
    long value

    A number of ticks that represent a time.

    Returns
    Type Description
    TimeSpan

    An object that represents value.

    GetHashCode()

    Returns the hash code for this instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A 32-bit signed integer hash code.

    Overrides
    object.GetHashCode()

    Negate()

    Returns a new TimeSpan object whose value is the negated value of this instance.

    Declaration
    public TimeSpan Negate()
    Returns
    Type Description
    TimeSpan

    A new object with the same numeric value as this instance, but with the opposite sign.

    Subtract(TimeSpan)

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

    Declaration
    public TimeSpan Subtract(TimeSpan ts)
    Parameters
    Type Name Description
    TimeSpan ts

    The time interval to be subtracted.

    Returns
    Type Description
    TimeSpan

    A new time interval whose value is the result of the value of this instance minus the value of ts.

    ToString()

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

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    The string representation of the current TimeSpan value.

    Overrides
    object.ToString()
    Remarks

    The returned string is formatted with the "c" format specifier and has the following format: [-][d.]hh:mm:ss[.fffffff]

    Operators

    operator +(TimeSpan, TimeSpan)

    Adds two specified TimeSpan instances.

    Declaration
    public static TimeSpan operator +(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to add.

    TimeSpan t2

    The second time interval to add.

    Returns
    Type Description
    TimeSpan

    An object whose value is the sum of the values of t1 and t2.

    operator ==(TimeSpan, TimeSpan)

    Indicates whether two TimeSpan instances are equal

    Declaration
    public static bool operator ==(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    operator >(TimeSpan, TimeSpan)

    Indicates whether a specified TimeSpan is greater than another specified TimeSpan.

    Declaration
    public static bool operator >(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    operator >=(TimeSpan, TimeSpan)

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

    Declaration
    public static bool operator >=(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    operator !=(TimeSpan, TimeSpan)

    Indicates whether two TimeSpan instances are not equal.

    Declaration
    public static bool operator !=(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    operator <(TimeSpan, TimeSpan)

    Indicates whether a specified TimeSpan is less than another specified TimeSpan.

    Declaration
    public static bool operator <(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    operator <=(TimeSpan, TimeSpan)

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

    Declaration
    public static bool operator <=(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The first time interval to compare.

    TimeSpan t2

    The second time interval to compare.

    Returns
    Type Description
    bool

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

    operator -(TimeSpan, TimeSpan)

    Subtracts a specified TimeSpan from another specified TimeSpan.

    Declaration
    public static TimeSpan operator -(TimeSpan t1, TimeSpan t2)
    Parameters
    Type Name Description
    TimeSpan t1

    The minuend.

    TimeSpan t2

    The subtrahend.

    Returns
    Type Description
    TimeSpan

    An object whose value is the result of the value of t1 minus the value of t2.

    operator -(TimeSpan)

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

    Declaration
    public static TimeSpan operator -(TimeSpan t)
    Parameters
    Type Name Description
    TimeSpan t

    The time interval to be negated.

    Returns
    Type Description
    TimeSpan

    An object that has the same numeric value as this instance, but the opposite sign.

    operator +(TimeSpan)

    Returns the specified instance of TimeSpan.

    Declaration
    public static TimeSpan operator +(TimeSpan t)
    Parameters
    Type Name Description
    TimeSpan t

    The time interval to return.

    Returns
    Type Description
    TimeSpan

    The time interval specified by t.

    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX