phptimetimezone

php shows one hour early


php settings in php.ini:

date.timezone = Asia/Jerusalem.

My Linux server (Ubuntu) shows the correct time: Wed Oct 1 15:35:39 IDT 2014

But when I echo date('Y-m-d H:i:s'); I get 2014-10-01 14:35:39 (One hour earlier).

I also tried to date_default_timezone_set('Asia/Jerusalem'); but the results are the same

Why is the result off?


Solution

  • Israel has undergone several changes to daylight saving time in the last few years. This year, DST is supposed to be in effect until October 26th. The last time the DST end date fell before October 1st was September 23, 2012. Reference here.

    When Israel announced the changes for 2013 forward, they were released in the standard IANA time zone database in version 2013d. I actually answered a similar question back then, regarding how Java handles this change.

    For PHP, the IANA database is implemented via the timezonedb PECL package. You can install this package manually to update to the latest version of the timezone data.

    PHP also comes with a copy of timezonedb internally, which is supposed to be the most recent version available at the time that the PHP version is released. So simply upgrading PHP to the latest version should also solve the problem.

    If you want to see what version of timezonedb you currently have (whether built-in, or updated) - you can call timezone_version_get(), as documented here. It needs to be at least 2013.4 to have this particular change. The current release is 2014.7.