Dennis9
asked on
Calculate to times??
Hi all.
I use this to calculate how long the oparation took:
...
Var
StartTime,
EndTime: TTime;
...
//When process starts
StartTime := Time;
...
//When process end
EndTime := (Time + StrToTime(timelabel.captio n)) - StartTime;
timelabel.caption := FormatDateTime('hh:nn:ss', EndTime);
It also work fine, but it don't calculate the seconds used. What i mean is that the process are not always very long ex. 1 sec. and then the timelabel is still 00:00:00
The process have to take more then 60 sec before something happens, on the timelabel.
I want to know, why it does not calculate the time correct?
Thanks.
Dennis
I use this to calculate how long the oparation took:
...
Var
StartTime,
EndTime: TTime;
...
//When process starts
StartTime := Time;
...
//When process end
EndTime := (Time + StrToTime(timelabel.captio
timelabel.caption := FormatDateTime('hh:nn:ss',
It also work fine, but it don't calculate the seconds used. What i mean is that the process are not always very long ex. 1 sec. and then the timelabel is still 00:00:00
The process have to take more then 60 sec before something happens, on the timelabel.
I want to know, why it does not calculate the time correct?
Thanks.
Dennis
Use the GetTickCount() function
var dProcess, dDif :Double;
begin
dProcess:=GetTickCount();
...;//something
dDif:=GetTickCount()-dProc ess;
ShowMessage('Finished in '+IntToStr(Trunc(dDif) div 60000)+' min, '+IntToStr((Trunc(dDif) mod 60000) div 1000)+' sec, '+IntToStr(Trunc(dDif) mod 1000)+' ms. ');
dProcess:=GetTickCount();
...; // ready gor next thing
begin
dProcess:=GetTickCount();
...;//something
dDif:=GetTickCount()-dProc
ShowMessage('Finished in '+IntToStr(Trunc(dDif) div 60000)+' min, '+IntToStr((Trunc(dDif) mod 60000) div 1000)+' sec, '+IntToStr(Trunc(dDif) mod 1000)+' ms. ');
dProcess:=GetTickCount();
...; // ready gor next thing
GetTickCount() is an API function which retrieves how miliseconds elapsed after the OS was started. The time is stored as a DWORD value. Therefore, the time will wrap around to zero if Windows is run continuously for 49.7 days.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sometimes you may need sub-milliseconds...
var
f,st,et: Int64;
begin
QueryPerformanceFrequency( f);
QueryPerformanceCounter(st );
// Do something here
QueryPerformanceCounter(et );
ShowMessage(Format('took %f microseconds,[((et-st)*100 0000)/f])) ;
end
var
f,st,et: Int64;
begin
QueryPerformanceFrequency(
QueryPerformanceCounter(st
// Do something here
QueryPerformanceCounter(et
ShowMessage(Format('took %f microseconds,[((et-st)*100
end
after seting the caption value add line in your code:
timelabel.repaint;
timelabel.repaint;
for measuring small time period less then milliseconds you can use zlrdtsc library from http://www.specosoft.com .
It with sorces and free.
It with sorces and free.
ASKER
Sorry i had forgot this.
I accept your answer because there i both get the hours, min, sec and mil.
Thanks all
I accept your answer because there i both get the hours, min, sec and mil.
Thanks all