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 array of format strings and culture-specific format information. The format of the string representation must match one of the specified formats exactly.
Assembly: mscorlib (in mscorlib.dll)
public static TimeSpan ParseExact( string input, string[] formats, IFormatProvider formatProvider )
Parameters
- input
- Type: System.String
A string that specifies the time interval to convert.
- formats
- Type:
System.String
[]
A array of standard or custom format strings that defines the required format of input.
- formatProvider
- Type: System.IFormatProvider
An object that provides culture-specific formatting information.
Return Value
Type: System.TimeSpanA time interval that corresponds to input, as specified by formats and formatProvider.
| Exception | Condition |
|---|---|
| ArgumentNullException | input is null. |
| FormatException | input has an invalid format. |
| OverflowException | input represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. -or- 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 one of the formats defined by the formats parameter, except that leading and trailing white-space characters are ignored.
The formats parameter is a string array whose elements consist of 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. input must correspond exactly to a member of formats for the parse operation to succeed.
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 returned by the CultureInfo.DateTimeFormat property defines the formatting of the returned string.
A DateTimeFormatInfo object that defines the formatting of the returned string.
A custom object that implements the IFormatProvider interface. Its IFormatProvider.GetFormat method returns a DateTimeFormatInfo object that provides formatting information.
If formatProvider is null, the DateTimeFormatInfo object that is associated with the current culture is used.