Reputation: 1641
In Australia, A client has been entering "1/5"
as a shortcut for the first day of May. We have just moved from Windows Server 2008 to Windows Server 2012.
Using the following code in LinqPad:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-au", false);
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern.Dump();
DateTime.Parse("1/5").Dump();
On Windows Server 2008:
dd MMMM
1/05/2016 12:00:00 AM
On Windows Server 2012 R2:
MMMM d
5/01/2016 12:00:00 AM
Questions:
DateTime.Parse
happening all through the system (Eg. Model Binding, Validation etc)Upvotes: 6
Views: 520
Reputation: 6864
I can replicate the issue on Windows Server 2012. If you add...
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();
you'll see it returns...
d/MM/yyyy
It's only the MonthDayPattern which seems to be incorrect. This might be a bug. I would log the issue on https://connect.microsoft.com/.
In the mean time you could simply set the MonthDayPattern....
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-au", false);
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern.Dump();
DateTime.Parse("1/5").Dump();
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern = "d MMMM";
DateTime.Parse("1/5").Dump();
On Windows Server 2012 R2:
d/MM/yyyy
MMMM d
5/01/2016 12:00:00 AM
1/05/2016 12:00:00 AM
Upvotes: 2