Having upgraded to Windows 8 RTM, some date time parsing code that I had has stopped working. I’ve replicated this using a standard console app:
CultureInfo provider;
provider = new CultureInfo("en-US");
string testDate = "1/1/2012";
DateTime date = DateTime.MinValue;
if (DateTime.TryParseExact(testDate,
CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, // (dd/MM/yyyy)
provider,
DateTimeStyles.None,
out date))
Console.WriteLine("Date: {0}", date);
else
Console.WriteLine("Can't parse date: {0} / {1}", testDate, date);
Console.ReadLine();
Outputs: Can't parse date: 1/1/2012 ...
I’ve also tried making the culture info “eb-GB” (as it makes no difference for the given format). However, if I change the input date to 01/01/2012, it works fine.
Has something changed in the .net 4.5 DateTime framework that affects this?
You need to change the
ShortDatePatternto use the one from the selected provider rather than the one inCurrentCulture.