Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A possible PHP bug with date_default_timezone_set and date?

Tags:

date

php

Suppose this code:

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

date_default_timezone_set('GMT');
$time = gmmktime(14, 50, 0, 5, 12, 2013);
echo date('Y-m-d H:i:s O', $time).'<br />';
echo gmdate('Y-m-d 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 on 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 time of the machine doesn't affect the output in any way.

Some info:

$ date +%Z
GMT
$ date +%z
+0000
  • PHP 5.3.25 (cli) (built: May 11 2013 09:54:00)
  • CentOS release 5.9 (Final)
like image 716
Dalius Avatar asked May 12 '13 15:05

Dalius


1 Answers

phpinfo() showed "Olson" Timezone Database Version as 0.system, so I used the command

pecl upgrade timezonedb

and added

extension=timezonedb.so

to php.ini

After restarting the server, the problem has been resolved with the new timezone DB version 2013.3

like image 135
Dalius Avatar answered Nov 12 '22 06:11

Dalius