TimeSpan::ToString Method (String^)


Converts the value of the current TimeSpan object to its equivalent string representation by using the specified format.

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

String^ ToString(
	String^ format


Type: System::String^

A standard or custom TimeSpan format string.

Return Value

Type: System::String^

The string representation of the current TimeSpan value in the format specified by the format parameter.

Exception Condition

The format parameter is not recognized or is not supported.

The format parameter can be any valid standard or custom format specifier for TimeSpan values. If format is equal to String::Empty or is null, the return value of the current TimeSpan object is formatted with the common format specifier ("c"). If format is any other value, the method throws a FormatException.

If format is a standard format string, the format of the returned string is defined by the formatting conventions of the current culture.


The custom format strings for TimeSpan values do not include a date or time separator. If you want to include these elements in your format string, you must treat them as character literals. See the example for an illustration, and see the Custom TimeSpan Format Strings topic for more information.

The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

The following example uses standard and custom TimeSpan format strings to display the string representation of each element in an array of TimeSpan values

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top