TimeSpan.ParseExact Method (String, String, IFormatProvider)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Converts the string representation of a time interval to its TimeSpan equivalent by using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.

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


Public Shared Function ParseExact ( _
    input As String, _
    format As String, _
    formatProvider As IFormatProvider _
) As TimeSpan
public static TimeSpan ParseExact(
    string input,
    string format,
    IFormatProvider formatProvider


  • format
    Type: System..::.String
    A standard or custom format string that defines the required format of input.

Return Value

Type: System..::.TimeSpan
A time interval that corresponds to input, as specified by format and formatProvider.


Exception Condition

input is nullNothingnullptra null reference (Nothing in Visual Basic).


input has an invalid format.


input represents a number that is less than TimeSpan..::.MinValue or greater than TimeSpan..::.MaxValue.


At least one of the days, hours, minutes, or seconds components in input is outside its valid range.


The ParseExact(String, String, IFormatProvider) method parses the string representation of a time interval, which must be in the format defined by the format parameter, except that leading and trailing white-space characters are ignored.

The format parameter is a string that contains either a single standard format specifier, or one or more custom format specifiers that define the required format of input. For more information about valid format strings, see Standard TimeSpan Format Strings and Custom TimeSpan Format Strings.

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:

If formatProvider is nullNothingnullptra null reference (Nothing in Visual Basic), the DateTimeFormatInfo object that is associated with the current culture is used.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1


Windows Phone

See Also


TimeSpan Structure

ParseExact Overload

System Namespace

Other Resources

Standard TimeSpan Format Strings

Custom TimeSpan Format Strings