TimeSpan.TryParseExact Method (String, array<String>[]()[], IFormatProvider, TimeSpan%)

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

Converts the specified string representation of a time interval to its TimeSpan equivalent by using the specified formats and culture-specific format information, and returns a value that indicates whether the conversion succeeded. The format of the string representation must match one of the specified formats exactly.

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

Syntax

Public Shared Function TryParseExact ( _
    input As String, _
    formats As String(), _
    formatProvider As IFormatProvider, _
    <OutAttribute> ByRef result As TimeSpan _
) As Boolean
public static bool TryParseExact(
    string input,
    string[] formats,
    IFormatProvider formatProvider,
    out TimeSpan result
)

Parameters

  • formats
    Type: array<System..::.String>[]()[]
    A array of standard or custom format strings that define the acceptable formats of input.
  • result
    Type: System..::.TimeSpan%
    When this method returns, contains an object that represents the time interval specified by input, or TimeSpan..::.Zero if the conversion failed. This parameter is passed uninitialized.

Return Value

Type: System..::.Boolean
true if input was converted successfully; otherwise, false.

Remarks

The TryParseExact(String, array<String>[]()[], IFormatProvider, TimeSpan%) 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. This method is similar to the ParseExact(String, array<String>[]()[], IFormatProvider) method, except that it does not throw an exception if the conversion fails.

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:

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

Platforms

Windows Phone

See Also

Reference

TimeSpan Structure

TryParseExact Overload

System Namespace

Other Resources

Standard TimeSpan Format Strings

Custom TimeSpan Format Strings