DateTimeToString procedure
Converts a
TDateTime value to a string with a given format.
Declaration
procedure DateTimeToString(out Result: string; const FormatStr: string;
const DateTime: TDateTime;
Options: TFormatDateTimeOptions=[])Description
DateTimeToString returns in
Result a string representation of
DateTime using the formatting specified in
FormatStr.
for a list of characters that can be used in the FormatStr formatting
string, see formatchars.
Note that for 'c', if the time part is 0 (i.e. midnight), no time is appended.
Note that on unix systems, the localization support must be enabled explicitly, see Localization.
Errors
In case a wrong formatting character is found, an EConvertError is raised.
See also
Example: ex4
Program Example4;
{ This program demonstrates the DateTimeToString function }
Uses sysutils;
Procedure today (Fmt : string);
Var S : AnsiString;
begin
DateTimeToString (S,Fmt,Date);
Writeln (S);
end;
Procedure Now (Fmt : string);
Var S : AnsiString;
begin
DateTimeToString (S,Fmt,Time);
Writeln (S);
end;
Begin
Today ('"Today is "dddd dd mmmm y');
Today ('"Today is "d mmm yy');
Today ('"Today is "d/mmm/yy');
Now ('''The time is ''am/pmh:n:s');
Now ('''The time is ''hh:nn:ssam/pm');
Now ('''The time is ''tt');
End.An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
