Converts the value of the current TimeSpan object to its equivalent string representation.
Assembly: mscorlib (in mscorlib.dll)
The returned string is formatted with the "c" format specifier and has the following format:
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. Note that the string returned by the method is not culture-sensitive.
A minus sign, which indicates a negative time interval. No sign is included for a positive time span.
The number of days in the time interval. This element is omitted if the time interval is less than one day.
The number of hours in the time interval, ranging from 0 to 23.
The number of minutes in the time interval, ranging from 0 to 59.
The number of seconds in the time interval, ranging from 0 to 59.
Fractional seconds in the time interval. This element is omitted if the time interval does not include fractional seconds. If present, fractional seconds are always expressed using seven decimal digits.
For more information about comparing the string representation of TimeSpan and Oracle data types, see Knowledge Base article 324577: System.TimeSpan Does Not Match Oracle 9i INTERVAL DAY TO SECOND Data Type.
Support for formatting TimeSpan values was added in the .NET Framework 4. However, the method overload remains culture-insensitive. Its behavior remains unchanged from previous versions of the .NET Framework. To control the formatting of a TimeSpan value, call the ToString(String) or ToString(String, IFormatProvider) overload.
The following example displays the strings returned by calling the ToString method with a number of TimeSpan values. Note that although the example does not call the ToString method directly, it is called by the Console.WriteLine method when it attempts to convert a TimeSpan value to its string representation.
Module ToString Public Sub Main() Dim span As TimeSpan ' Initialize a time span to zero. span = TimeSpan.Zero Console.WriteLine(span) ' Initialize a time span to 14 days. span = New TimeSpan(-14, 0, 0, 0, 0) Console.WriteLine(span) ' Initialize a time span to 1:02:03. span = New TimeSpan(1, 2, 3) Console.WriteLine(span) ' Initialize a time span to 250 milliseconds. span = New TimeSpan(0, 0, 0, 0, 250) Console.WriteLine(span) ' Initalize a time span to 99 days, 23 hours, 59 minutes, and 59.9999999 seconds. span = New TimeSpan(99, 23, 59, 59, 999) Console.WriteLine(span) ' Initalize a time span to 3 hours. span = New TimeSpan(3, 0, 0) Console.WriteLine(span) ' Initalize a timespan to 25 milliseconds. span = New TimeSpan(0, 0, 0, 0, 25) Console.WriteLine(span) End Sub End Module ' The example displays the following output: ' 00:00:00 ' -14.00:00:00 ' 01:02:03 ' 00:00:00.2500000 ' 99.23:59:59.9990000 ' 03:00:00 ' 00:00:00.0250000
.NET FrameworkSupported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.