On 20 July 2016 at 15:52, Denis Kozlov <[email protected]> wrote:
>
> So, below is a tidy cross-platform implementation of NowUTC:
>
Oops, forgot the milliseconds, here it is:
function NowUTC: TDateTime;
{$ifdef WINDOWS}
var
SystemTime: TSystemTime;
begin
Windows.GetSystemTime(SystemTime);
Result := SystemTimeToDateTime(SystemTime);
end;
{$else}
{$ifdef UNIX}
var
tp: timeval;
begin
fpgettimeofday(@tp,nil);
Result := UnixToDateTime(tp.tv_sec);
Result := IncMilliSecond(Result, tp.tv_usec div 1000);
end;
{$else}
begin
// WARNING: Suffers from a race condition!
Result := LocalTimeToUniversal(Now);
end;
{$endif}
{$endif}
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel