C# DateTime Parse and ParseExact using IFormatProvider in ASP.Net

C# DateTime Parse and ParseExact functions provides the functionality to convert the DateTime string value into DateTime object according the specified culture info. C# IFormatProvider interface enables you to get the culture based information and passes it to the Parse or ParseExact DateTime function. IFormatProvider interface not only validates the DateTime string value and the specified format specifiers, instead it also checks whether the specified format belongs the selected culture or not.

Instructions

Try the following sample to convert the DateTime string to DateTime value based on the selected culture:

1. First DropDownList control contains the list of various ASP.Net Framework supported cultures. Choose a culture name according to your native culture to test this sample.

2. It will fill the valid DateTime format specifiers in the second DropDownList control.

3. Enter a DateTime string value that should match any one of the Culture based Formats available in the second DropDownList control.

4. Click the Get Format button to convert the string to DateTime value. If it will display the output value then your specified DateTime string value is valid according the selected Culture.

Note: Some cultures may show errors if your string value language is different from chosen culture.

Now Try the Sample

Select Culture:
Valid Formats:
[Format Specifiers]
Enter DateTime:
Output: