DateTime.ParseExact Method (String, String, IFormatProvider)
Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.
Assembly: mscorlib (in mscorlib.dll)
static member ParseExact : s:string * format:string * provider:IFormatProvider -> DateTime
A string that contains a date and time to convert.
A format specifier that defines the required format of s. For more information, see the Remarks section.
An object that supplies culture-specific format information about s.
Return ValueType: System.DateTime
An object that is equivalent to the date and time contained in s, as specified by format and provider.
If s does not represent a time in a particular time zone and the parse operation succeeds, theKind property of the returned DateTime value is DateTimeKind.Unspecified. If s does represent the time in a particular time zone and format allows time zone information to be present (for example, if format is equal to the "o", "r", or "u" standard format specifiers, or if it contains the "z", "zz", or "zzz" custom format specifiers), the Kind property of the returned DateTime value is DateTimeKind.Local.
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 s. For details about valid formatting codes, see Standard Date and Time Format Strings or Custom Date and Time Format Strings.
If format is a custom format pattern that does not include date or time separators (such as "yyyyMMddHHmm"), use the invariant culture for the provider parameter and the widest form of each custom format specifier. For example, if you want to specify hours in the format pattern, specify the wider form, "HH", instead of the narrower form, "H".
The particular date and time symbols and strings (such as names of the days of the week in a particular language) used in s are defined by the provider parameter, as is the precise format of s if format is a standard format specifier string. The provider parameter can be any of the following:
A DateTimeFormatInfo object that defines the format of date and time data.
If provider is null, the CultureInfo object that corresponds to the current culture is used.
Notes to Callers:
In the .NET Framework 4, the ParseExact method throws a FormatException if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1