Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TimeSpan::ToString Method

Updated: April 2009

Returns the string representation of the value of this instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

virtual String^ ToString() override

Return Value

Type: System::String
A string that represents the value of this instance. The return value is of the form:
Elements in square brackets ([ and ]) may not be included in the returned string. Colons and periods (: and.) are literal characters. The non-literal elements are listed in the following table.




A minus sign, which indicates a negative time span. No sign is included for a positive time span.


The number of days in the time span. This element is omitted if the time span is less than one day.


The number of hours in the time span, ranging from 0 to 23.


The number of minutes in the time span, ranging from 0 to 59.


The number of seconds in the time span, ranging from 0 to 59.


Fractional seconds in the time span. This element is omitted if the time span does not include fractional seconds. If present, fractional seconds are always expressed using 7 decimal digits.


For more information about comparing the string representation of TimeSpan and Oracle data types, see article Q324577, "System.TimeSpan Does Not Match Oracle 9i INTERVAL DAY TO SECOND Data Type," in the Microsoft Knowledge Base at

The return value of this method can be consumed by Parse.

Note that the ToString method does not include an overload that includes format specifiers and provides precise control over the returned string. To define the precise format of the returned string, you can format a TimeSpan object's individual property values, as the following example shows. For more information, see Numeric Format Strings.

No code example is currently available or this language may not be supported.

The following example displays the strings returned by calling the ToString method with a number of TimeSpan values.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0




April 2009

Replaced the duplicated Visual Basic example.

Customer feedback.

July 2008

Revised the explanation of the format of the returned string; added examples.

Customer feedback.

Community Additions

© 2017 Microsoft