LostOne
asked on
Integer into timer?
What is the best/easiest way to convert an integer to a timer format 00:00:00? The integer is increased every second. All I need is a simple timer that I can display in a label.
Thanks
Thanks
ASKER
I want to show a timer that starts at 00:00:01 and increases every second.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that would work from 0 to 60 seconds but not after that.
59 sec would be 00:00:59
1 min would be 00:01:00
1 hour would be 01:00:00
the format i'm looking for is [hour]:[min]:[sec]
59 sec would be 00:00:59
1 min would be 00:01:00
1 hour would be 01:00:00
the format i'm looking for is [hour]:[min]:[sec]
Wait ....this one is better without using integers, but real DateTime type..
var
StartTime : TDateTime;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := FormatDateTime('hh:nn:ss', Time - StartTime);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StartTime := Time;
end;
Hope this is what you're looking for ;-)
Regards,
Viktor Ivanov
var
StartTime : TDateTime;
procedure TForm1.Timer1Timer(Sender:
begin
Label1.Caption := FormatDateTime('hh:nn:ss',
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StartTime := Time;
end;
Hope this is what you're looking for ;-)
Regards,
Viktor Ivanov
Actually you can do it with integers the way you wanted, but you need to play a little with the if then conditions....
var
h, m, s : Byte;
begin
Inc(s);
if s > 9 then
Label1.Caption := '00:00:' + IntToStr(s)
else if s > 60 then
begin
Inc(m);
if m > 9 then
Label1.Caption := '00:'+IntToStr(m) +':'+IntToStr(i)
else
Label1.Caption := '00:0'+IntToStr(m) +':'+IntToStr(i);
end
else
Label1.Caption := '00:00:0' + IntToStr(s);
end;
and so on...you got the idea...
Regards,
Viktor Ivanov
var
h, m, s : Byte;
begin
Inc(s);
if s > 9 then
Label1.Caption := '00:00:' + IntToStr(s)
else if s > 60 then
begin
Inc(m);
if m > 9 then
Label1.Caption := '00:'+IntToStr(m) +':'+IntToStr(i)
else
Label1.Caption := '00:0'+IntToStr(m) +':'+IntToStr(i);
end
else
Label1.Caption := '00:00:0' + IntToStr(s);
end;
and so on...you got the idea...
Regards,
Viktor Ivanov
Have a timer and set the Interval to 1000 milisecs..then enter this code in the OnTimer()
Label1.Caption := TimeToStr(Time);
Is this what you need?? I mean is it the time or date that you want to show??