TFormatSettings (Delphi)
Description
The following code example illustrates the usage of TFormatSettings with different time locales.
Code
procedure Test;
var
str1, str2: string;
FS: TFormatSettings;
strResult, strFormat: TStringBuilder;
begin
strResult := TStringBuilder.Create;
strFormat := TStringBuilder.Create;
FS := TFormatSettings.Create('en-US');
strFormat.AppendFormat('%s %s', [FS.LongDateFormat, FS.LongTimeFormat]);
str1 := FormatDateTime(strFormat.ToString, Now());
strResult.AppendLine(str1);
//A second instance with a different locale (used for comparison)
FS := TFormatSettings.Create('ro-RO');
strFormat.Clear;
strFormat.AppendFormat('%s %s', [FS.LongDateFormat, FS.LongTimeFormat]);
str2 := FormatDateTime(strFormat.ToString, Now());
strResult.AppendLine(str2);
writeLn(strResult.ToString);
end;
end;