I’m doing some globalization work in my current project and I came across a curious behavior. I’m running on Windows 7 with only English-US installed, and my app is running on .NET 3.5.
Given the following snippet:
var culture = new CultureInfo("zh-CN", true);
var formats = culture.GetAllDateTimePatterns('D');
Under .NET 4, the following formats are returned:
yyyy'年'M'月'd'日'
yyyy'年'M'月'd'日',dddd
dddd,yyyy'年'M'月'd'日'
Which is what the Date and time formats dialog in the Control Panel shows (what I was aiming for).
But on .NET 3.5 (and earlier) the following is returned:
yyyy'年'M'月'd'日'
yyyy-MM-dd
dddd, yyyy-MM-dd
dddd, yyyy'年'M'月'd'日'
I went and checked what values were returned using EnumDateFormatsExEx (and earlier versions), and it matched .NET 4’s results.
The difference doesn’t bother me; my question is why are the results different? I assumed the underlying implementation was calling out to EnumDateFormatsExEx or similar, but after I fired up Ilspy I didn’t see anything of that sort. I wanted to show the same list that appears in the Control Panel, so I was surprised when the formats came out different. I figured the format list would come from the OS, and not differ between run-time versions.
The relevant changes in .NET 4 are documented here. Highlighting: