PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone php
在用PHP5.3以上的PHP版本時,只要是涉及時間的會報一個 apache
"PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. ide
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 ui
misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in"
這樣的錯。如何解決呢 this
實際上,從 PHP 5.1.0 ,當對使用date()等函數時,若是timezone設置不正確,在每一次調用時間函數時,都會 ip
產生E_NOTICE 或者 E_WARNING 信息。而又在php5.1.0中,date.timezone這個選項,默認狀況下是關閉的,無 get
論用什麼php命令都是格林威治標準時間,可是PHP5.3中好像若是沒有設置也會強行拋出了這個錯誤的,解決此問 io
題,只要本地化一下,就好了。 function
如下是三種方法(任選一種都行):
1、在頁頭使用date_default_timezone_set()設置 date_default_timezone_set('PRC'); //東八時區 echo
date('Y-m-d H:i:s');
2、在頁頭使用 ini_set('date.timezone','Asia/Shanghai');
3、修改php.ini。打開php5.ini查找date.timezone 去掉前面的分號修改爲爲:date.timezone =PRC
重啓http服務(如apache2或iis等)便可。
XXX能夠任意正確的值。對於咱們國內來講:能夠爲如下值:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi
(依次爲重慶,上海,烏魯木齊)港臺地區可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次爲澳門
,香港,臺北),還有新加坡:Asia/Singapore,固然PRC也行。