Incorrect PHP date / time

PHP date() and time() return the wrong time:

When date.timezone = "Europe/Riga" time returned by date() was 03-12-2011 08:57:12 , but the system time was 03-12-2011 01:57:12 (the time zone Europe / Riga is right time at that moment). When I changed the time zone to β€œEurope / London”, the time changed to 03-12-2011 06:57:12 (actual time 02-12-2011 23:57:12 )

The time returned by date / hwclock --show was correct ( 03-12-2011 01:57:12 with the system time zone set in Riga)

OS: Debian 6.0

I checked most of the questions regarding similar questions on SO / Google, but all of them did not seem to indicate the wrong time zone.

As far as I can tell, there is a problem between php -> os. Of course, since the wrong time offset is always constant, I could subtract the difference, but this is not the right solution.

Any ideas would be highly appreciated.

+7
source share
6 answers

The problem is similar to what I saw on one of my servers. Looks like a bug in php 5.3.2-1 . Try running php script in the error report and post the results.

+3
source

Reading the PHP manual it seems that the behavior of date.timezone depends on the settings in php.ini. There is another way to set the default time zone for all date and time functions, and date_default_timezone_set . Try installing it with:

 date_default_timezone_set('Europe/Riga'); 

instead of your date.timezone code.

+10
source

System time zone may be incorrect. This leads to a time shift set by the PHP date () function, although php date.timezone (in php.ini) and the server system time are true.

+2
source

I had problems with the time zone. It may be convenient for someone.

In my case, Chile, Sumer Time CLST returned the wrong time offset.

Timezonedb worked for me.

Follow the link: https://pecl.php.net/package/timezonedb

For Widnows Download the latest version of the dll, copy it to the "ext" directory. Edit php.ini and put the line below:

extension = php_timezonedb.dll

For Linux, you can use:

pecl install timezonedb

and in php.ini put:

extension = php_timezonedb.so

+1
source

You must set date.timezone in php.ini and restart the server http://php.net/manual/en/timezones.php

-2
source

PHP time is based on a timeline that uses GMT and later UTC. Most people now refer to it as unix time. Since PHP uses unix time, time zones are not used. I believe that subtracting time zone hours in seconds is the right method to correct for differences.

-4
source

All Articles