Skip to content
Advertisement

My localhost Apache2 PHP UTC has a minute delay

I am trying to set the timezone for my Apache PHP server to get the UTC, and it tells everything is ok, but the datetime I get when retrieving dates is wrong.

I have set in the php.ini the date.timezone like this:

date.timezone=UTC

The info shown realated to date:

phpinfo();

enter image description here

But the real UTC datetime is 1 minutes ahead, so for example if i run

echo date('Y-m-d H:i:s');

I get 2020-05-06 23:59:11 and real UTC is 2020-05-07 00:00:11

I need this to be precise because of Google 2FA Authenticator, to match the codes.

Any suggestion will be well received! Thanks

Advertisement

Answer

Most computer clocks are not perfect at keeping time and will naturally drift one way or the other over time. This is why we have NTP to synchronize our clocks with special clocks that are accurate, and NTPd to keep our local clocks in sync.

How to synchronize your system clock is highly dependent on your OS, with several different flavors of NTPd. If you have further questions about how to specifically configure NTP/NTPd for your OS they would be best asked on https://superuser.com/.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement