Click or drag to resize

Duration Methods

The Duration type exposes the following members.

Methods
  NameDescription
Public methodCompareTo
Compares this instance against another Duration instance based on the bytes representation of the values.
Public methodEquals(Object)
Returns true if the value of the Duration is the same.
(Overrides ValueTypeEquals(Object).)
Public methodEquals(Duration)
Returns true if the value of the Duration is the same.
Public methodStatic memberFromTimeSpan
Creates a new Duration instance based on the TimeSpan provided.

Consider that 24 hour days (no leap seconds) are used to calculate the days portion.

Public methodGetHashCode
Returns the hash code for this instance.
(Overrides ValueTypeGetHashCode.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberParse
Creates a new Duration instance from the string representation of the value.

Accepted formats:

  • multiple digits followed by a time unit like: 12h30m where the time unit can be:
    • y: years
    • m: months
    • w: weeks
    • d: days
    • h: hours
    • m: minutes
    • s: seconds
    • ms: milliseconds
    • us or µs: microseconds
    • ns: nanoseconds
  • ISO 8601 format:
    P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W
  • ISO 8601 alternative format:
    P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]
Public methodToIsoString
A string representation of this duration using ISO-8601 based representation, such as PT8H6M12.345S.
Public methodToString
Returns the string representation of the value.
(Overrides ValueTypeToString.)
Public methodToTimeSpan
Returns a TimeSpan instance that represents the same interval than this instance.

You should take into consideration that TimeSpan is internally represented in ticks, so for the conversion, 24h days will be used (leap seconds are not considered). For Duration values with month portion, it will throw an InvalidOperationException.

Top
See Also