Sign in Join

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

Mailing lists / lazarus / 2011-07

How to get UTC time

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Petr Hlozek

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I need to get UTC time from my system. Using Ubuntu 10.04 with fpc 2.4.0.

Trying this function:

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

It's working but it returns right time only for the first time. Next calling utc_now() returns the same time as before.

Does anybody know what is wrong?

Thank you!

Petr
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOLBimAAoJEFxZOIHWsemF27QIAJJbhwMGligZhzA7zuwaFoc8 sJzXlIF5RNnn6Jj4cii5RtFFIe64c+3RM5lXq7mSPOX6t20KtUucG5oCe+lkekIP wQWvvwiVmEXjOazGQAW5JWRy821S5FSYTySFseqW0W6lO0Qby7duUgZMC4zJTsha DM/ZIBbvjVuNs36ckPxsYu2T+h6jqRTcqbfD1XGBnj13Zi8TjbMdOCacfZuAIxZt u8nxvLQStCl0DD7Rtx7MdSb1+Ygir0jU7/PQ/GLqpkt4P6iOAg4mE8kSpe1ZPCGi 6DlGas3cD9KnuDRg81pbslKrb1fPb0IBkj95UUAI+rZQ1F5hHXwwdD+irgz9tL8= =4WAF
-----END PGP SIGNATURE-----

Reply by email