[fpc-pascal] Getting UTC time etc.

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sat Jul 28 22:59:18 CEST 2012

Mark Morgan Lloyd wrote:
> I know that this was discussed a couple of months ago, but I had 
> difficulty working out what the consensus was.
> i)    Is there an FPC function which will get the raw time from the RTC, 
> which on unix systems will usually be UTC (specifically, without a DST 
> correction)?

Discussion was in March. How time flies. Reinier et al. suggested 
PascalTZ, but in the end I went for a simple function since I'm trying 
to avoid installing anything special and timezone info will be available 
from the backend database.

   (* This from FPC-Pascal mailing list, 13/02/07. Thanks, Marco. 
   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;

> ii)    Are there functions to get "Unix seconds", "Borland seconds" and 
> so on? Preferably without DST correction, or with the correction being 
> extractable?

DateTimeToUnix() from DateUtils. Anything else I can do without.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the fpc-pascal mailing list