Skip to content
CShift0.32

TimeSpan

Struct · namespace System · Since 0.19

struct TimeSpan : IComparable<TimeSpan>, IEquatable<TimeSpan>, IHashable

A duration (or a time of day): a signed number of ticks of 100 ns, like .NET’s TimeSpan (with methods instead of properties).

TimeSpan t = TimeSpan.Create(1, 30, 0); // 01:30:00
Console.WriteLine(t.TotalMinutes()); // 90
TimeSpan left = deadline.Subtract(DateTime.Now());
Name Description
Ticks The duration in ticks of 100 ns.
int64 Ticks

The duration in ticks of 100 ns.

Name Description
FromTicks A duration of ticks ticks (100 ns each).
FromDays A duration of days days (rounded to whole ticks).
FromHours A duration of hours hours (rounded to whole ticks).
FromMinutes A duration of minutes minutes (rounded to whole ticks).
FromSeconds A duration of seconds seconds (rounded to whole ticks).
FromMilliseconds A duration of milliseconds milliseconds (rounded to whole ticks).
Create A duration of the given hours, minutes and seconds.
static TimeSpan FromTicks(int64 ticks)

A duration of ticks ticks (100 ns each).

static TimeSpan FromDays(double days)

A duration of days days (rounded to whole ticks).

static TimeSpan FromHours(double hours)

A duration of hours hours (rounded to whole ticks).

static TimeSpan FromMinutes(double minutes)

A duration of minutes minutes (rounded to whole ticks).

static TimeSpan FromSeconds(double seconds)

A duration of seconds seconds (rounded to whole ticks).

static TimeSpan FromMilliseconds(double milliseconds)

A duration of milliseconds milliseconds (rounded to whole ticks).

static TimeSpan Create(int hours, int minutes, int seconds)

A duration of the given hours, minutes and seconds.

static TimeSpan Create(int days, int hours, int minutes, int seconds)

A duration of the given days, hours, minutes and seconds.

static TimeSpan Create(int days, int hours, int minutes, int seconds, int milliseconds)

A duration of the given days, hours, minutes, seconds and milliseconds.

Name Description
Days The days part of the duration.
Hours The hours part of the duration (-23 to 23).
Minutes The minutes part of the duration (-59 to 59).
Seconds The seconds part of the duration (-59 to 59).
Milliseconds The milliseconds part of the duration (-999 to 999).
TotalDays The whole duration in days, with fractions.
TotalHours The whole duration in hours, with fractions.
TotalMinutes The whole duration in minutes, with fractions.
TotalSeconds The whole duration in seconds, with fractions.
TotalMilliseconds The whole duration in milliseconds, with fractions.
Add The sum of this duration and other.
Subtract This duration minus other.
Negate The duration with the opposite sign.
Duration The absolute value of the duration.
Multiply The duration times factor (rounded to whole ticks).
CompareTo Compares the lengths of the durations (IComparable).
Equals Whether the durations are equal (IEquatable).
GetHashCode A hash code of the duration (IHashable).
ToString The duration as text, like .NET’s "c" format: [-][d.]hh:mm:ss[.fffffff], e.g. 1.02:03:04.5000000.
int Days()

The days part of the duration. The parts have the sign of the whole: -1.02:03:04 has the days -1, the hours -2, …

int Hours()

The hours part of the duration (-23 to 23).

int Minutes()

The minutes part of the duration (-59 to 59).

int Seconds()

The seconds part of the duration (-59 to 59).

int Milliseconds()

The milliseconds part of the duration (-999 to 999).

double TotalDays()

The whole duration in days, with fractions.

double TotalHours()

The whole duration in hours, with fractions.

double TotalMinutes()

The whole duration in minutes, with fractions.

double TotalSeconds()

The whole duration in seconds, with fractions.

double TotalMilliseconds()

The whole duration in milliseconds, with fractions.

TimeSpan Add(TimeSpan other)

The sum of this duration and other.

TimeSpan Subtract(TimeSpan other)

This duration minus other.

TimeSpan Negate()

The duration with the opposite sign.

TimeSpan Duration()

The absolute value of the duration.

TimeSpan Multiply(double factor)

The duration times factor (rounded to whole ticks).

int CompareTo(TimeSpan other)

Compares the lengths of the durations (IComparable).

bool Equals(TimeSpan other)

Whether the durations are equal (IEquatable).

int GetHashCode()

A hash code of the duration (IHashable).

string ToString()

The duration as text, like .NET’s "c" format: [-][d.]hh:mm:ss[.fffffff], e.g. 1.02:03:04.5000000.