Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 04/01/25 in Posts

  1. Remy Lebeau

    FormatDateTime in Delphi 12

    You are using the version of FormatDateTime() that relies on global variables initialized with your PC's locale settings. For instance, the '/' specifier is not a literal slash character, it is a placeholder that uses the global DateSeparator variable in the SysUtils unit. This is documented behavior. You can update those globals to customize things like the date/time separators, but this affects the whole app, and is not thread-safe. When you need custom formatting that is locale-agnostic, you should use the version of FormatDateTime() that takes a TFormatSettings parameter, eg: procedure TForm1.Button1Click(Sender: TObject); var lDate: TDateTime; lFmt: TFormatSettings; begin lFmt := TFormatSettings.Create; lFmt.DateSeparator := '/'; lDate := EncodeDate(2025, 3, 26); Edit1.Text := FormatDateTime('dd/mm/yyyy', lDate, lFmt); end; The alternative is to wrap desired literal text with quotes in your format string, eg: procedure TForm1.Button1Click(Sender: TObject); var lDate: TDateTime; begin lDate := EncodeDate(2025, 3, 26); Edit1.Text := FormatDateTime('dd"/"mm"/"yyyy', lDate); end;
  2. David Millington pointed me to a solution, through the support of Embarcadero: This solved the problem for me.
×