php shows one hour early

后端 未结 5 1883
予麋鹿
予麋鹿 2020-12-22 13:00

php settings in php.ini:

date.timezone = Asia/Jerusalem.

My Linux server (Ubuntu) shows the correct time:

相关标签:
5条回答
  • 2020-12-22 13:10

    You solve it by setting the timezone explicitly in your PHP scripts. You can do this with date_default_timezone_set():

    date_default_timezone_set('Asia/Jerusalem');
    

    Here is the list of PHP supported timezones.

    You may also want to try a test script calling date_default_timezone_get() to see what it's actually set to to verify that this is in fact the problem.

    List of Supported Timezones

    0 讨论(0)
  • 2020-12-22 13:15

    Change the php timezone:

    1) Open the php.ini file - vim /etc/php.ini

    2) Change the default timezone settings by adding/modifying this line:

    date.timezone = Asia/Jerusalem - remove the ; at the first of line (if exists)!

    3) Save the php.ini file.

    4) Restart the Apache server - systemctl restart httpd.service. The timezone settings should now be modified.

    0 讨论(0)
  • 2020-12-22 13:16

    The Asia/Jerusalem timezone has daylight savings time currently in effect; it may be that php isn't handling this. The function call date('I') will return 1 if your php is currently running DST, 0 otherwise.

    0 讨论(0)
  • 2020-12-22 13:20

    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.

    0 讨论(0)
  • 2020-12-22 13:29

    Set and check your time zone in php.

    <?php
      date_default_timezone_set('America/Los_Angeles'); // here set the time zone
    
      $script_tz = date_default_timezone_get();
    
      if (strcmp($script_tz, ini_get('date.timezone'))){
         echo 'Script timezone differs from ini-set timezone.';
      } else {
         echo 'Script timezone and ini-set timezone match.';
      }
    ?>
    
    0 讨论(0)
提交回复
热议问题