[Lazarus] Portable way to get accurate timestamps?
Petr Kristan
petr.kristan at epos.cz
Wed Feb 23 13:17:46 CET 2011
On Sun, Feb 20, 2011 at 02:46:34PM +0100, Luca Olivetti wrote:
> Al 20/02/11 12:42, En/na Bo Berglund ha escrit:
>
> > I wonder if GetTickCount will get me a better value to milliseconds
> > than Now()?
>
> Not under linux:
>
> function GetTickCount: DWord;
> begin
> Result := DWord(Trunc(Now * 24 * 60 * 60 * 1000));
> end;
My Linux version:
function GetTickCount: Cardinal;
var
ts: TTimeSpec;
i: Int64;
begin
if clock_gettime(CLOCK_MONOTONIC, @ts) <> 0 then begin //kernels 2.4.* does not support
Result := 0;
Exit;
end;
i := ts.tv_sec;
i := i*1000 + ts.tv_nsec div 1000000;
Result := i and $ffffffff; //cut to unsig 32bit
end;
Petr
--
Petr Kristan
.
EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice
tel: +420 466335223 Czech Republic (Eastern Europe)
fax: +420 466510709
More information about the Lazarus
mailing list