I don’t understand. Why is overloading using IFormatProvider in DateTime.ParseExact ?
If I determine exactly how it should be parsed (spaces, delimiters, etc.), then the problem will not be a problem:
All these 3 examples show the same result:
example 1
CultureInfo provider =CultureInfo.CreateSpecificCulture("en-US"); var t= DateTime.ParseExact("13-2-2013", "dM-yyyy", provider, DateTimeStyles.None); Console.WriteLine (t);
example 2
CultureInfo provider =CultureInfo.CreateSpecificCulture("en-US"); var t= DateTime.ParseExact("13/2/2013", "d/M/yyyy", provider, DateTimeStyles.None); Console.WriteLine (t);
example 3
CultureInfo provider =CultureInfo.CreateSpecificCulture("en-US"); var t= DateTime.ParseExact("13@@@2@@@2013", "d@@@M@@@yyyy", provider, DateTimeStyles.None); Console.WriteLine (t); //13/02/2013 00:00:00
So why do I need to provide a provider if I explicitly define the structure?
Royi namir
source share