Delphi: plain hh: mm: ss Timer

Does anyone have a short and efficient code for hh: mm: ss timer (Timer1.Interval: = 1000)? I can do one, but I want something effective.

Thank!

My code is:

Var MyTime:TTime;

MyTime:=EncodeTime(0,0,0,0);

procedure TForm1.Timer1Timer(Sender: TObject);
begin
MyTime:=incsecond(Mytime,1);
form1.Label1.Caption:='Time: '+TimeToStr(MyTime);
end;
+5
source share
1 answer

Add A Var to track timer start.

  TForm1 = class(TForm)
  private
    timerStart: TDateTime;
  public
    proceure StartTimer;
  end;

Procedure To Start A Timer

proceure TForm1.StartTimer;
beign
 timerStart := now();
 timer1.interval = 1000;
 timer1.enabled := true;
end;

In the OnTimer event

Label1.caption := formatdatetime('hh:nn:ss', timerStart - now()); //nn is for minutes.

This should display the correct time for any interval.
those. 5000 to show every 5 seconds, time.

. , 24 . , datetime - dd hh:nn:ss

+8

All Articles