The provider specifies the culture-specific format information about the date.
For example, you could pass in any of these cultures:
new CultureInfo("en-US") // USA
new CultureInfo("fr-FR") // France
new CultureInfo("it-IT") // Italy
new CultureInfo("de-DE") // Germany
And you would get the date formatted according to those cultures, such as:
- en-US: 6/1/2009 4:37:00 PM
- fr-FR: 01/06/2009 16:37:00
- it-IT: 01/06/2009 16.37.00
- de-DE: 01.06.2009 16:37:00
Another example: using the "d" format, which represents the M/d/yyyy short date pattern when using en-US for CultureInfo, consider:
DateTime dateValue;
string[] sampleDates = new[] { "31/8/2009", "8/31/2009" };
foreach (string currentDate in sampleDates)
{
bool result = DateTime.TryParseExact(currentDate, new[] {"d"},
new CultureInfo("en-US"),
DateTimeStyles.None,
out dateValue);
Console.WriteLine("{0}: {1}", currentDate, result ? "valid" : "invalid");
if (result)
{
Console.WriteLine("Result: {0}", dateValue);
}
Console.WriteLine();
}
Output:
31/8/2009: invalid
8/31/2009: valid
Result: 8/31/2009 12:00:00 AM
31/8/2009 is invalid since it doesn't fit the en-US culture format of M/d/yyyy, whereas 8/31/2009 is valid since it does.