如何确定自应用程序启动以来的运行时间?
最佳答案
尝试 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.
关于delphi - 如何获得我的应用程序运行时间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8610107/