「delphi」取得電腦開機時間

 1,816 total views,  2 views today

取得電腦開機的時間,也是很簡單的耶

[delphi]function UpTime: string;
const
ticksperday: Integer = 1000 * 60 * 60 * 24;
ticksperhour: Integer = 1000 * 60 * 60;
ticksperminute: Integer = 1000 * 60;
tickspersecond: Integer = 1000;
var
t: Longword;
d, h, m, s: Integer;
begin
t := GetTickCount;
d := t div ticksperday;
Dec(t, d * ticksperday);
h := t div ticksperhour;
Dec(t, h * ticksperhour);
m := t div ticksperminute;
Dec(t, m * ticksperminute);
s := t div tickspersecond;
Result := ‘已開機: ‘ + IntToStr(d) + ‘ 天 ‘ + IntToStr(h) + ‘ 小時 ‘ + IntToStr(m) +
‘ 分 ‘ + IntToStr(s) + ‘ 秒’;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
ShowMessage(UpTime);
end;[/delphi]

發表迴響

%d 位部落客按了讚: