C# - dateTime.ToLocalTime().ToString("MMM dd") abbreviated month doesn't works with Korean language

Anderson Rodrigues Cavalcante 271 Reputation points
2022-01-31T21:04:00.737+00:00

The format MMM to the month doesn't format Jan, Fev, Mar... to Korean date.
For example:
DateTime date = new DateTime(2022, 1, 31);
date.ToLocalTime().ToString("MMM dd"); //=> "1 31"

The same problem using other way.
CultureInfo ci = CultureInfo.CreateSpecificCulture("ko-KR");
DateTimeFormatInfo dtfi = ci.DateTimeFormat;
dtfi.AbbreviatedMonthNames // => {"01","02","03","04","05","06", ...}

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,268 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,036 Reputation points
    2022-02-01T00:27:47.52+00:00

    Interesting that when querying SQL-Server via

    SELECT dateformat,name, alias, months FROM sys.syslanguages WHERE alias = 'Korean'
    

    The correct results are returned. Seems a hack for C# would be to create your own class as it's unlikely AbbreviatedMonthNames is going to change any time soon.

    A starter

    public class Korean
    {
        private static readonly CultureInfo _cultureInfo = CultureInfo.CreateSpecificCulture("ko-KR");
        private static readonly DateTimeFormatInfo _dateTimeFormatInfo = _cultureInfo.DateTimeFormat;
    
        public static string[] AbbreviatedMonthNames()
        {
            _dateTimeFormatInfo.AbbreviatedMonthNames = new[] 
                { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "" };
            _dateTimeFormatInfo.AbbreviatedMonthGenitiveNames = _dateTimeFormatInfo.AbbreviatedMonthNames;
            return _dateTimeFormatInfo.AbbreviatedMonthGenitiveNames.Take(12).ToArray();
        }
    }