Month abbreviations show 4 characters instead of 3

395 Views Asked by At

I have in code

string dateStr = dateTime.ToString("dd-MMM-yyyy");

On my Windows 11 machine instead of "21-Sep-2021" it generates month with 4 character abbreviation “21-Sept-2021”.

It is generated correctly as 3 characters on the server and other developers machines. https://learn.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo.abbreviatedmonthnames?view=net-7.0#property-value

I didn’t find where I can change settings. I played with settings as suggested in https://pureinfotech.com/change-time-date-windows-11/ But everything looks ok, Localisation shows “English-Australia”

I’ve confirmed that Australia has 3 characters month abbreviation https://lh.2xlibre.net/locale/en_AU/ and on page https://lh.2xlibre.net/values/abmon/ no localization has 4 character months abbreviations.

I am curious which setting can cause this behaviour?

As a workaround I explicitly specified InvariantCulture

 dateTime.ToString("dd-MMM-yyyy",CultureInfo.InvariantCulture);
1

There are 1 best solutions below

0
Panagiotis Kanavos On BEST ANSWER

That's actually ...... not wrong, although it may not be correct.

From the Australian Government Style Manual, Dates and time

The standard abbreviations for the months are:

  • ...
  • September – ‘Sept’
  • ...

On Windows 11, with NET (Core) 8, using dotnet-repl, this script :

var dateTime=new DateTime(2023,9,21);
var cults=CultureInfo.GetCultures(CultureTypes.AllCultures)
            .Where(ci=>dateTime.ToString("dd-MMM-yyyy",ci)=="21-Sept-2023");
foreach(var cult in cults)
{
    Console.WriteLine("{0} {1}",cult.Name,cult.DisplayName);
}

Produces

en-AU English (Australia)
en-GB English (United Kingdom)

MMM is the specifier for the month abbreviation, not just the first three letters of a month, just as MMMM is the specifier for the full name.

Windows is used by end users, not just developers, so I suspect there were bugs filed that Windows applications don't produce the official abbreviations, even if they aren't the most common ones used in a country.

I've seen similar questions about en-ZA (South Africa) and en-ZW (Zimbabwe). In at least one case both . and , were used as digit separators. One official, one not.