這篇文章主要介紹了解決php的「It is not safe to rely on the system's timezone settings」問題的方法,需要的朋友可以參考下
如果使用PHP5.3以上版本時,如果沒有正確的配置php.ini就會出現PHP日期函數的錯誤。以前很多舊的PHP程式設計教學都沒有說到這個問題,所以不少讀者會覺得困惑,以下筆者為大家講述解決這個問題的三種方法。
"PHP Warning:
date() [function.date]: It is not safe to rely on the system's timezone settings.
You are *required* to use the date.
timezone 字_ortime In case you used any of those methods and you are still getting this warning,
you most likely misspelled the timezone identifier.
We selected 'UTC' for '8.0/no DST' insteadier.
We selected 'UTC' for '8.0/no DST' insteadier.We selected 'UTC' for '8.0/no DST' instead instead" .0,當對使用date() 等函數時,如果timezone 設定不正確,在每一次呼叫時間函數時,都會產生E_NOTICE 或E_WARNING 資訊。而又在PHP 5.1.0 中,date.timezone 這個選項,預設情況下是關閉的,無論用什麼PHP 指令都是格林威治標準時間,但是PHP 5.3 中好像如果沒有設定也會強行拋出了這個錯誤的,解決此問題,只要本地化一下就行了。
一、在頁頭使用date_default_timezone_set()設定 date_default_timezone_set('PRC'); //東八時區 echo
date('Y-m-d H:i:s');
二、在頁頭使用ini_set('date.timezone','Asia/Shanghai');
三、修改php.ini(如果是windows 系統,那麼檔案在C 盤,Windows 目錄下,假如係統是安裝在C 盤)。使用記事本打開 php.ini 查找 date.timezone 去掉前面的分號修改成為:date.timezone = "Asia/Shanghai"
重啟php或http服務(如apache2或iis等)即可!
以上三種方法可以選擇其中一種即可,小編推薦使用第三種方法,不用每次都要增加額外的程式碼。