Possible PHP error with date_default_timezone_set and date?

Assume this code:

<?php date_default_timezone_set('UTC'); $time = gmmktime(14, 50, 0, 5, 12, 2013); echo date('Ymd H:i:s O', $time).'<br />'; echo gmdate('Ymd H:i:s O', $time).'<br />'; date_default_timezone_set('GMT'); $time = gmmktime(14, 50, 0, 5, 12, 2013); echo date('Ymd H:i:s O', $time).'<br />'; echo gmdate('Ymd H:i:s O', $time); ?> 

On my local server, I get the output:

 2013-05-12 14:50:00 +0000 2013-05-12 14:50:00 +0000 2013-05-12 14:50:00 +0000 2013-05-12 14:50:00 +0000 

But in production, the same code produces:

 2013-05-12 10:50:00 -0400 2013-05-12 14:50:00 +0000 2013-05-12 14:50:00 +0000 2013-05-12 14:50:00 +0000 

Changing the operating time of the device does not affect the output.

Some information:

 $ date +%Z GMT $ date +%z +0000 
  • PHP 5.3.25 (cli) (built: May 11, 2013 09:54:00)
  • CentOS Version 5.9 (Final)
+6
source share
2 answers

phpinfo () showed the version of the Timezone database "Olson" as 0.system, so I used the command

 pecl upgrade timezonedb 

and added

 extension=timezonedb.so 

in php.ini

After restarting the server, the problem was resolved with the new version of the TDzone 2013.3 database.

+1
source

Perhaps this is not about code.

If “O” is the GMT difference in hours, the time setting on the work computer may not be set correctly.

0
source

Source: https://habr.com/ru/post/944817/


All Articles