The GetTickCount Windows API function retrieves the number of milliseconds that have elapsed since the system was started (up to 49.7 days).
If you need to display how many days (minutes, seconds) have passed since Windows have been started, you need to convert miliseconds to days, hours, minutes.
function WindowsUpTime : string ; function MSecToTime(mSec: Integer): string; const secondTicks = 1000; minuteTicks = 1000 * 60; hourTicks = 1000 * 60 * 60; dayTicks = 1000 * 60 * 60 * 24; var D, H, M, S: string; ZD, ZH, ZM, ZS: Integer; begin ZD := mSec div dayTicks; Dec(mSec, ZD * dayTicks) ; ZH := mSec div hourTicks; Dec(mSec, ZH * hourTicks) ; ZM := mSec div hourTicks; Dec(mSec, ZM * minuteTicks) ; ZS := mSec div secondTicks; D := IntToStr(ZD) ; H := IntToStr(ZH) ; M := IntToStr(ZM) ; S := IntToStr(ZS) ; Result := D + '.' + H + ':' + M + ':' + S; end; begin Result := MSecToTime(GetTickCount) ; end;
Note: the “WindowsUpTime” returns a string formatted as “days.hours:minutes:seconds”, for example: “1.12:30:12″, if Windows have been running for the last 1 day, 12 hours, 30 minutes and 12 seconds.
Posted in
Good algorithm!, but there is an error in line 16. The correct line is:
ZM := mSec div minuteTicks;