Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-07

Getting UTC time etc.

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

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)?

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

I'm trying to work out a fairly large distributed system, and while the backend databases will generally be able to supply UTC I'd like to be able to get it from the client for status messages etc. before connection.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 6 lines
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;
   var
     timeval: TTimeVal;
     timezone: PTimeZone;
     a: Double;
   begin
     TimeZone := nil;
     fpGetTimeOfDay (@TimeVal, TimeZone);
     // Convert to milliseconds
     a := (TimeVal.tv_sec * 1000.0) + (TimeVal.tv_usec / 1000.0);
     Result := (a / MSecsPerDay) + UnixDateDelta;
   end;
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]

Reply by email