TimeSpan.ToString Method (String, IFormatProvider)
Converts the value of the current TimeSpan object to its equivalent string representation by using the specified format and culture-specific formatting information.
Assembly: mscorlib (in mscorlib.dll)
abstract ToString : format:string * formatProvider:IFormatProvider -> string override ToString : format:string * formatProvider:IFormatProvider -> string
- Type: System.IFormatProvider
An object that supplies culture-specific formatting information.
Return ValueType: System.String
The string representation of the current TimeSpan value, as specified by format and formatProvider.
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 a null reference (Nothing in Visual Basic), 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.
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:
For more information about support for formatting in the .NET Framework, see Formatting Types.
The formatProvider parameter is an IFormatProvider implementation that provides culture-specific information about the format of the returned string. The formatProvider parameter can be any of the following:
A CultureInfo object that represents the culture whose formatting conventions are to be reflected in the returned string. The DateTimeFormatInfo object retuned by the CultureInfo.DateTimeFormat property defines the formatting of the returned string.
A DateTimeFormatInfo object that defines the formatting of the returned string.
If formatProvider is a null reference (Nothing in Visual Basic), the DateTimeFormatInfo object that is associated with the current culture is used. If format is a custom format string, the formatProvider parameter is ignored.
The following example calls the method to format two time intervals. The example calls the method twice for each format string, first to display it using the conventions of the en-US culture and then to display it using the conventions of the fr-FR culture.