標籤:
轉載:http://www.shangxueba.com/jingyan/121682.html
在用PHP5.3以上的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 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 ‘UTC‘ for ‘8.0/no DST‘ instead in..."
實際上,從 PHP 5.1.0 ,當對使用date()等函數時,如果timezone設定不正確,
在每一次調用時間函數時,都會產生E_NOTICE 或者 E_WARNING 資訊。
而又在php5.1.0中,date.timezone這個選項,預設情況下是關閉的,
無論用什麼php命令都是格林威治標準時間,但是PHP5.3中好像如果沒有設定也會強行拋出了這個錯誤的,解決此問題,只要本地化一下,就行了。
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。開啟php5.ini尋找date.timezone 去掉前面的分號修改成為:date.timezone =PRC
重啟http服務(如apache2或iis等)即可。
XXX(如:PRC)可以任意正確的值。對於我們國內來說:
可以為以下值:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次為重慶,上海,烏魯木齊)
港台地區可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次為澳門,香港,台北),
還有新加坡:Asia/Singapore,當然PRC也行
php使用date()函數時,提示的警告