如何找出自应用程序启动以来我的应用程序运行的时间?
答案 0 :(得分:17)
尝试GetProcessTimes
功能
{$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.