user917170
user917170

Reputation: 1641

DateTimeFormatInfo.MonthDayPattern Has Changed in Windows Server 2012 - How Can I set it back?

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:

  1. Why has the MonthDayPattern changed? Australians always have day first, then month
  2. Where can this be set in the Windows Server UI? The UI only exposes the long and short formats, not the month and day format
  3. How can I fix the issue in my application with the least amount of changes, given that there could be DateTime.Parse happening all through the system (Eg. Model Binding, Validation etc)

Upvotes: 6

Views: 520

Answers (1)

Mick
Mick

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

Related Questions