Search code examples
windowsdelphiwinapidelphi-10.2-tokyo

How to display formatted month names?


Some languages such as Czech or Slovak alter their spelling based on the context of its usage. However FormatDateTime does not have as many options as SimpleDateFormat in Java, where you can switch between formatted MMMM and standalone form LLLL of the month.

I'm using this notation which displays standalone form 30. leden 2019 instead of formatted form 30. ledna 2019. I suppose there should be some Windows function but I can't find it and I'd like to avoid writing my own library.

FormatDateTime('d. mmmm yyyy', Today);

Solution

  • GetDateFormat

    var
      DateStr: array[byte] of Char;
    
    begin
       GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, nil, nil, DateStr, 256);
       Writeln(DateStr);
    

    For Russian locale this returns correct phrase: 31 января 2019 г. (not nominative январь)

    GetDateFormat($405, DATE_LONGDATE, nil, nil, DateStr, 256);
    

    For Czech locale LCID=$405 it returns 31. ledna 2019