RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.DateTimeToStr Function

Converts a TDateTime value to a string.

Pascal
function DateTimeToStr(const DateTime: TDateTime): string; overload;
function DateTimeToStr(const DateTime: TDateTime; const FormatSettings: TFormatSettings): string; overload;
C++
AnsiString DateTimeToStr(const TDateTime DateTime);
AnsiString DateTimeToStr(const TDateTime DateTime, const TFormatSettings FormatSettings);

SysUtils

The first form of DateTimeToStr is not thread-safe, because it uses localization information contained in global variables. The second form of DateTimeToStr, which is thread-safe, refers to localization information contained in the FormatSettings parameter. Before calling the thread-safe form of DateTimeToStr, you must populate FormatSettings with localization information. To populate FormatSettings with a set of default locale values, call GetLocaleFormatSettings.  

C++ Examples: 

 

/*
This example uses a label and a button on a form. When the
user clicks the button, the current date and time is
converted to a string and displayed as the caption of the
label:
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Label1->Caption = DateTimeToStr(Now());
}

 

Delphi Examples: 

{
This example uses a label and a button on a form. When the
user clicks the button, the current date and time is
converted to a string and displayed as the caption of the
label:
} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := SysUtils.DateTimeToStr(Now);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!