PHP調試的時候出現了警告
PHP調試的時候出現了警告:
It is not safe to rely on the system解決方法,其實就是時區設置不正確造成的,本文提供了3種方法來解決這個問題。
實際上,從PHP 5.1.0開始當對使用date()等函數時,如果timezone設置不正確,在每一次調用時間函數時,都會產生E_NOTICE 或者 E_WARNING 信息,而又在php中,date.timezone這個選項,默認情況下是關閉的,無論用什麽php命令都是格林威治標準時間,但是PHP5.3中如果沒有設置部分時間類函數也會強行拋出了這個錯誤的。
PS:現在由於大部分人使用VPS/雲主機,需要自己配置的環境的就更加會容易出現這個情況。
方法1:
(最好的方法)在php.ini裏加上找到date.timezone項,設置date.timezone = "Asia/Shanghai",重啟環境就ok了。
方法2:
在需要用到這些時間函數的時候,在頁面添加date_default_timezone_set("PRC");
方法3:
在頁頭加上設置時區ini_set(‘date.timezone‘,‘Asia/Shanghai‘);
錯誤代碼:
Warning: 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 ‘Asia/Chongqing’ for ‘CST/8.0/no DST’ instead
Warning: 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 ‘Asia/Chongqing’ for ‘CST/8.0/no DST’ instead
Warning: date_default_timezone_get(): 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 ‘Asia/Chongqing‘ for ‘CST/8.0/no DST‘ instead in <b>/home/ftp/n/nimaboke/include/lib/function.base.php
PHP調試的時候出現了警告