RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.Time Function

Returns the current time.

Pascal
function Time: TDateTime;
C++
TDateTime Time();

Time and GetTime return the current time as a TDateTime value. The two functions are completely equivalent.

Note: Time clashes with an Xlib function of the same name. Use GetTime in Linux and cross-platform code.
 

C++ Examples: 

 

/*
This procedure displays the current time in the form's
caption every time the Timer's OnClick event fires, based upon
the Interval Property (default: 1000 = 1 sec)
*/
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  TDateTime DateTime = Time();  // store the current date and time
  AnsiString str = TimeToStr(DateTime); // convert the time to a string
  Caption = str;  // display the time on the form's caption
  // Note This could have been done with the following line of code:
  //  Caption = TimeToStr(Time());
}

 

Delphi Examples: 

{
This procedure displays the current time in the form's
caption every time the Timer's OnClick event fires, based upon
the Interval Property (default: 1000 = 1 sec)
}
procedure TForm1.Timer1Timer(Sender: TObject);
var
  DateTime : TDateTime;
  str : string;
begin
  DateTime := Time;  // store the current date and time
  str := TimeToStr(DateTime); // convert the time into a string
  Caption := str;  // display the time on the form's caption
  { Note This could have been done with the following line of code:
    Caption := TimeToStr(Time); }
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!