SysUtilsTimeToStr (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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).

Code

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;

Uses