ChrisHDog
ChrisHDog

Reputation: 4663

Why did .ToString("MMM dd yyyy") go from "Jul" to "July" (aka how do I report a bug / see change log for .net)

Prior to recent Windows 11 Update when I had code that was DateTime.Now.ToString("MMM dd yyyy") the output would be "Jul 12 2022" but recently it has started to produce "July 12 2022" (this is on the same machine; with culture en-AU before and after the update)

It appears to only be when one does that with more than just "MMM" i.e. DateTime.Now.ToString("MMM") still produces "Jul" but adding the "dd yyyy" makes it "July"

This looks to be some odd combination of culture specific and Windows 11 Updates as: I still get "Jul" if: machine is running Windows 10, machine is set to en-US; but if Windows 11 and latest updates and en-AU then "July 12 2022" for "MMM dd yyyy"

The "easy" solution (if you've come here and are en-AU and having the same issue) is to add CultureInfo.Invariant to the call: so DateTime.Now.ToString("MMM dd yyyy", CultureInfo.Invariant)

The extended questions are:

Upvotes: 2

Views: 470

Answers (1)

DavidG
DavidG

Reputation: 119017

So this isn't a bug with .NET or Windows 11, it's really a quirk of how dates are represented in text form. Date formats in .NET support the concept of genitive names for month names. In certain cultures the way the month is written changes depending on how you write it out. In English there is no difference but in a language like Latvian for example, writing "January" and "14th January" will result in different spellings ("janvāris" and "janvārī")

If you look at the DateTimeFormat for a CultureInfo object, you will see two properties: AbbreviatedMonthNames and AbbreviatedMonthGenitiveNames. They are arrays of how each month is represented in text form. For en-GB, both of those arrays are the same and contain Jan', Feb, Mar` etc.

However, for some reason, Windows 11 has a different set of names for some months and uses 4 letters for June, July and Sept.

So this code:

var culture = CultureInfo.CreateSpecificCulture("en-AU");
Console.WriteLine(culture.DateTimeFormat.AbbreviatedMonthGenitiveNames[6]);

Will output Jul in Windows 10 and July in Windows 11. Why they are different, I have no idea!

Upvotes: 1

Related Questions