Fix: Now() returns incorrect time on iOS device, due to a FPC RTL bug

Posted by on in Blogs
Due to a FPC RTL bug, the Now(), Time() and possibly Date() functions return an incorrect time unless you're actually in GMT.

A possible fix:

var
TZOffsetFromGMT : Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
TZOffsetFromGMT := NSTimeZone.localTimeZone.secondsFromGMT;
end;

use it later as follows:

var
Hour, Min, Sec, MSec : Word;
CurrTime : TDateTime;
begin
CurrTime := Now+TZOffsetFromGMT/3600.0/24.0;
DecodeTime(CurrTime,Hour,Min,Sec,MSec);

...

end;


Comments

  • Guest
    Allen Bauer Thursday, 20 October 2011

    Just to be clear... this is the fault of the FPC RTL, and *NOT* the official Delphi RTL.

  • Guest
    Anders Ohlsson Thursday, 20 October 2011

    Yes! I figured that. I'll edit the post in a bit.

    Thanks Allen!

  • Guest
    Jim Robertson Thursday, 20 October 2011

    Where do I find the source for your Monday session?

    Regards,
    Jim

  • Guest
    Anders Ohlsson Thursday, 20 October 2011

    Probably next week.

  • Guest
    Jonas Maebe Thursday, 20 October 2011

    Please do report any FPC bugs you find in the FPC bug tracker at http://bugs.freepascal.org

    Not doing so makes it much more likely that we'll miss them and that they won't be fixed in future versions.

    Thanks!

  • Guest
    Jonas Maebe Monday, 24 October 2011
  • Guest
    Anders Ohlsson Monday, 24 October 2011

    Thanks, Jonas!

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: