PHP調試的時候出現了警告:php
It is not safe to rely on the system解決方法,其實就是時區設置不正確形成的,本文提供了3種方法來解決這個問題。ide
實際上,從PHP 5.1.0開始當對使用date()等函數時,若是timezone設置不正確,在每一次調用時間函數時,都會產生E_NOTICE 或者 E_WARNING 信息,而又在php中,date.timezone這個選項,默認狀況下是關閉的,不管用什麼php命令都是格林威治標準時間,可是PHP5.3中若是沒有設置部分時間類函數也會強行拋出了這個錯誤的。
PS:如今因爲大部分人使用VPS/雲主機,須要本身配置的環境的就更加會容易出現這個狀況。
建議:不熟悉PHP環境仍是用比較成熟的一鍵安裝包吧。函數
方法1:ui
(最好的方法)在php.ini里加上找到date.timezone項,設置date.timezone = "Asia/Shanghai",重啓環境就ok了。this
方法2:調試
在須要用到這些時間函數的時候,在頁面添加date_default_timezone_set("PRC");get
方法3:io
在頁頭加上設置時區ini_set('date.timezone','Asia/Shanghai');function
錯誤代碼:
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.phprequire