解決 PHP 5.3.0 + WordPress 造成 It is not safe to rely on the system’s timezone settings.

Author: Eric  //  Category: Free Teaching

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /Path_to_your/www/wp-includes/functions.php on line 35

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /Path_to_your/www/wp-includes/functions.php on line 43

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /Path_to_your/www/wp-includes/functions.php on line 35

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /Path_to_your/www/wp-includes/functions.php on line 43

00. 大多看到這問題發生在您用的是 PHP 5.3.0 或使用套裝軟體搭配的 PHP 版本是 5.3.0。

01. 下面為解決的方法, 則一使用即可, 依推薦使用的順序排序。

  1. 修改 ./wp-config.php, 加上

date_default_timezone_set('Asia/Taipei');

  2. 修改 ./wp-includes/functions.php

    a. 在第一個 function 前面加上

date_default_timezone_set('UTC+8');

    b. 在第一個 function 前面加上

date_default_timezone_set('Asia/Taipei');

  3. 修改 php.ini, 加上

date.timezone = "Asia/Taipei"

02. 上面的 Asia/Taipei 均可以替換成下面任一城市, 其它城市請到 PHP timezones 尋找

日本 : Asia/Tokyo
台北 : Asia/Taipei
重慶 : Asia/Chongqing
漢城 : Asia/Seoul
上海 : Asia/Shanghai
新加坡 : Asia/Singapore
澳門 : Asia/Macao 或 Asia/Macau
香港 : Asia/Hong_Kong 或 Asia/Chungking

03. 上面所提到的套裝軟體為 AppServ, PHPnow, XAMPP, WampServer, APMServ, EasyPHP

Ref:
01. WordPress Support
02. PHP date_default_timezone_set

Tags: , , , , , , , , , ,

6 Responses to “解決 PHP 5.3.0 + WordPress 造成 It is not safe to rely on the system’s timezone settings.”

  1. 万戈 Says:

    还没碰到过这个情况,先收藏了,以备不测

  2. 1v77 Says:

    我通过第二条 修改 ./wp-includes/functions.php后,现实的不是这种错误了,而是Only variables should be passed by reference,不知道这又是哪里的问题?

  3. Eric Says:

    請問一下, 您是加在如下面的位置嗎?

    <?php
    /**
    * Main WordPress API
    *
    * @package WordPress
    */

    /**
    * ......
    * ......
    */
    date_default_timezone_set('UTC+8');

    function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
    .....
    }

    ....
    ?>

    如果答案是"Yes"的話, 那請把 +8 去掉看看
    如果答案是"Yes"的話, 那其它的方法您有試過嗎?

  4. 1v77 Says:

    我就是加在那里的,出现的那个错误,想用第一种方法,修改./wp-config.php,可是不知道那段代码加到哪里...

  5. Eric Says:

    您可以加在 define ('WPLANG', ''); 的前面或後面

  6. 1v77 Says:

    还是上面我说的那种错误,应该是服务器禁用了一些函数...我直接下载到电脑上吧...

Leave a Reply