Sign in Join
FPDoc Onlineexperiment

FormatDateTime function

In unit sysutils

Return a string representation of a TDateTime value with a given format.

Declaration

pascal
function FormatDateTime(const FormatStr: string; DateTime: TDateTime; 
 Options: TFormatDateTimeOptions=[]): string

Description

FormatDateTime formats the date and time encoded in DateTime according to the formatting given in FormatStr. The complete list of formatting characters can be found in formatchars.

When the format string is empty, 'c' is used instead.

Note that on unix systems, the localization support must be enabled explicitly, see Localization.

Errors

On error (such as an invalid character in the formatting string), and EConvertError exception is raised.

See also

Example: ex14

pascal
Program Example14;

{ This program demonstrates the FormatDateTime function }

Uses sysutils;

Var ThisMoment : TDateTime;

Begin
  ThisMoment:=Now;
  Writeln ('Now : ',FormatDateTime('hh:nn',ThisMoment));
  Writeln ('Now : ',FormatDateTime('DD MM YYYY',ThisMoment));
  Writeln ('Now : ',FormatDateTime('c',ThisMoment));
End.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.