[fpc-devel] Problem with Now() and time changed by ntpd
    Hans-Peter Diettrich 
    DrDiettrich1 at aol.com
       
    Fri Nov  4 12:50:07 CET 2011
    
    
  
Sven Barth schrieb:
> var
>   st: TSystemTime;
>   dt: TDateTime;
> begin
>   GetLocalTime(st);
>   dt := SystemTimeToDateTime(st);
>   Writeln(FormatDateTime('c', dt));
>   GetSystemTime(st);
>   dt := SystemTimeToDateTime(st);
>   Writeln(FormatDateTime('c', dt));
>   Readln;
> end.
> 
> === source end ===
> 
> As long as your time zone isn't UTC you will see two different times.
Okay, when you get the *decoded* date/time, the conversion into 
TDateTime is straight forward. [I missed that the WinAPI provides both 
times in that format].
But then I wonder why you *ever* want to convert TSystemTime into 
TDateTime, when it will be converted back again in the date/time 
formatting (and other) procedures. It would be much faster to display or 
write out a time stamp, based directly on TSystemTime.
POSIX gettimeofday() instead does not return a decoded date/time, so 
that Delphi uses localtime_r() to decode it. The inverse function must 
be used then, to decode a TDateTime for display and other date/time 
handling. When the RTL implements both these procedures, there should 
not remain any time difference in the Now() and other procedures on 
Windows and Linux, based on something like an tick count.
DoDi
    
    
More information about the fpc-devel
mailing list