[fpc-pascal] How to get UTC time

Marco van de Voort marcov at stack.nl
Tue Feb 13 21:25:31 CET 2007

> for me.  It needs both the SysUtils and Libc units, which I'm already using 
> for other declarations anyway.

Libc is a legacy unit, better use the proper (portable) units, and you'll
spare yourself a libc dependancy, AND make it portable across unices:

{$mode Delphi}
uses unix,sysutils,baseunix;

 function utc_now : TDateTime;
   timeval: TTimeVal;
   timezone: PTimeZone;
   a: Double;
   TimeZone := nil;
   fpGetTimeOfDay (@TimeVal, TimeZone);
   // Convert to milliseconds
   a := (TimeVal.tv_sec * 1000.0) + (TimeVal.tv_usec / 1000.0);
   Result := (a / MSecsPerDay) + UnixDateDelta;

More information about the fpc-pascal mailing list