Search code examples
delphidelphi-10.2-tokyo

FormatSettings.ShortDateFormat not the same as System Locale


I'm getting current format settings by doing:

 _FormatSettings := TFormatSettings.Create(GetThreadLocale);

My system short date format is dd.MM.yyyy but _FormatSettings.shorDateFormat is dd/MM/yyyy. Should I replace slashes with FormatSettings date separator or I am not aware of something else?

I'm using Windows 10 with latest updates.

My actual short date format is:

Actual locale short date format


Solution

  • No, you should not replace the slashes in TFormatSettings.ShortDateFormat. That could cripple the date formulation.

    The '/' character in TFormatSettings.ShortDateFormat is a placeholder for the actual date separator character (TFormatSettings.DateSeparator), that will be inserted during formulation of a date string.

    Ref.

    procedure DateTimeToString(var Result: string; const Format: string; DateTime: TDateTime; const AFormatSettings: TFormatSettings);

    in System.SysUtils