Does anybody have a short and effective code for hh:mm:ss timer (Timer1.Interval:=1000)? I can make one but I want something efficient.
Thanks!
My Code:
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;
Add A Var to keep track of when the timer started.
TForm1 = class(TForm)
private
timerStart: TDateTime;
public
proceure StartTimer;
end;
The procedure To start the 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 show the correct time taken for any interval.
i.e. 5000 to show every 5 seconds, the time taken.
Note: With out testing, running the timer for longer than 24 hours might not show the correct time difference. For that I think that the datetime format string should be something like dd hh:nn:ss
to show the days passed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With