How to find out the time that my application is running since it started?
Try the GetProcessTimes
function
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows,
SysUtils;
function FileTime2DateTime(FileTime: TFileTime): TDateTime; //Convert then FileTime to TDatetime format
var
LocalTime: TFileTime;
DOSTime : Integer;
begin
FileTimeToLocalFileTime(FileTime, LocalTime);
FileTimeToDosDateTime(LocalTime, LongRec(DOSTime).Hi, LongRec(DOSTime).Lo);
Result := FileDateToDateTime(DOSTime);
end;
Var
lpCreationTime, lpExitTime, lpKernelTime, lpUserTime: TFileTime;
begin
try
GetProcessTimes(GetCurrentProcess,lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
Sleep(1000); //do something
Writeln(Format('Running Time %s',[FormatDateTime('hh:nn:ss.zzz',Now-FileTime2DateTime(lpCreationTime))]));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
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