PHP 的 timezone settings

在 PHP 升級到 5.3 後, 在使用日期相關的 functions 時會出現類似以下的錯誤訊息:

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

解決方法分別可以透過修改 php.ini 或 php 程式碼實現:
1. 修改 php.ini
在 php.ini 加入一行:
date.timezone = “Asia/Hong_Kong”

儲存後需要重新啟動 web server.

2. 修改 php 程式碼
在 php 程式的最開諯加入以下一行語法:

date_default_timezone_set(‘Asia/Hong_Kong’);

上面所使用的 “Asia/Hong_Kong” 代表香港的時區, 其他時區可以到 PHP Timezone 尋找。


Leave a Reply