php如何設定時間,php.ini如何設定時間,PHP Warning: date() [function.date]:
It is not safe to rely on the system's timezone
在用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.time
zone 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"
都是timezone惹的禍。
這個問題,從 PHP 5.1.0 ,當對使用date()等函數時,如果date.timezone設定不正確,在每一次調用時間函數時,都會產生E_NOTICE 或者 E_WARNING 資訊。而又在php5.1.0中,date.timezone這個選項,預設情況下是關閉的,無論用什麼php命令都是格林威治標準時間,但是PHP5.3中好像如果沒有設定也會強行拋出了這個錯誤的,解決此問題,只要設定一下timezone,就行了。
以下是data問題的三種解決方案:
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也行。