Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Running in TTimer?

Status
Not open for further replies.

ug505

Programmer
Jan 2, 2010
52
0
0
US
I've tried searching Google without any luck for my problem. My program has a label that tells you how long you have been running the program. I can only get it to show in seconds (using a TTimer.) How could I somehow convert those seconds into hours:minutes:seconds format?
 
You could do the math yourself. There are also library routines available out there that will do that for you.

What have you tried so far?
 
var
TimeStart: TDateTime;

procedure TForm1.FormCreate(Sender: TObject);
begin
TimeStart:= Now;
end;

procedure UpdateTime;
var
T: TDateTime;
begin
T:= Now - TimeStart;
Label1.Caption:= FormatDateTime('h:n:s.zzz', T);
//format: 5:30:13.230 (Hours / Minutes / Seconds / Milliseconds)
end;

You may also instead want to make use of GetTickCount instead of Now - it calculates milliseconds based on processor up-time rather than the actual date/time.


JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top