Creates a DateTime from a string and uses DateTimeFormatInfo to format it with DateTimeStyles enumeration.
[Visual Basic] Overloads Public Shared Function ParseExact( _ ByVal s As String, _ ByVal format As String, _ ByVal dtfi As DateTimeFormatInfo, _ ByVal style As DateTimeStyles _ ) As DateTime [C#] public static DateTime ParseExact( string s, string format, DateTimeFormatInfo dtfi, DateTimeStyles style ); [C++] public: static DateTime ParseExact( String* s, String* format, DateTimeFormatInfo* dtfi, DateTimeStyles style ); [JScript] public static function ParseExact( s : String, format : String, dtfi : DateTimeFormatInfo, style : DateTimeStyles ) : DateTime;
A DateTime formatted in the valid string representation and style.
Exception Type | Condition |
---|---|
ArgumentNullException | If the string is a null reference (in Visual Basic Nothing). |
FormatException | If the string does not contain a valid string representation of a date and time. |
FormatException | If the format uses the general format ("G") string. |
The Parse and ParseExact methods each break the input into smaller chunks, but the ParseExact also looks for a specific (exact) string.
ParseExact constructs a DateTime from a string. The string must specify a date and, optionally, a time in a culture-specific or universal format. See CultureInfo and DateTimeFormatInfo for a list of the format characters.
DateTimeStyles provides the particular parsing flags that are used.
Leading and trailing white space characters are allowed.
An unexpected FormatException occurs while using the ToString general format ("G") string when the general format DateTime string representation is not parsed correctly.
DateTime Structure | DateTime Members | System Namespace | DateTime.ParseExact Overload List | String | DateTimeFormatInfo | DateTimeFormat