Jump to content

[Delphi] Detect How Long Windows Has Been Running

- - - - -

  • Please log in to reply
No replies to this topic

#1
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 763 posts
Windows API GetTickCount supplies information of how long Windows has run in milliseconds. The following code will read that information and parse it into more readable format (hours, minutes, seconds, and milliseconds).


procedure TForm1.BitBtn1Click(Sender: TObject);

var

  vTick    : Cardinal;

  vHours   : Integer;

  vMinutes : Integer;

  vSeconds : Integer;

  vMiliSecs: Integer;

  vTime    : string;

begin

  vTick := GetTickCount;


  vHours   := vTick div (3600*1000);  // extract the elapsed hours

  vMinutes := (vTick mod (3600*1000)) div (60*1000); // extract the minutes

  vSeconds := (vTick mod (60*1000)) div 1000;  // extract the seconds

  vMiliSecs:= vTick mod 1000;  // extract the milliseconds


  // format that values into more readable format

  vTime := Format('%d:%d:%d.%d', [vHours, vMinutes, vSeconds, vMiliSecs]);


  // show the info in a dialog

  ShowMessage(vTime);

end;


Will show some dialog like this:
[ATTACH]3613[/ATTACH]

Attached Files






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users