PHP Warning: date(): It is not safe to rely on the system's timezone settings
在用PHP5.3以上的PHP版本時(shí),只要是涉及時(shí)間的會(huì)報(bào)一個(gè)
"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"這樣的錯(cuò)。如何解決呢
實(shí)際上,從 PHP 5.1.0 ,當(dāng)對(duì)使用date()等函數(shù)時(shí),如果timezone設(shè)置不正確,在每一次調(diào)用時(shí)間函數(shù)時(shí),都會(huì)產(chǎn)生E_NOTICE 或者 E_WARNING 信息。而又在php5.1.0中,date.timezone這個(gè)選項(xiàng),默認(rèn)情況下是關(guān)閉的,無論用什么php命令都是格林威治標(biāo)準(zhǔn)時(shí)間,但是PHP5.3中好像如果沒有設(shè)置也會(huì)強(qiáng)行拋出了這個(gè)錯(cuò)誤的,解決此問題,只要本地化一下,就行了。
以下是三種方法(任選一種都行):
一、在頁頭使用date_default_timezone_set()設(shè)置 date_default_timezone_set('PRC');//東八時(shí)區(qū) echo date('Y-m-d H:i:s'); 二、在頁頭使用 ini_set('date.timezone','Asia/Shanghai'); 三、修改php.ini。打開php5.ini查找date.timezone 去掉前面的分號(hào)修改成為:date.timezone =PRC重啟http服務(wù)(如apache2或iis等)即可。
XXX可以任意正確的值。對(duì)于我們國內(nèi)來說:可以為以下值:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次為重慶,上海,烏魯木齊)港臺(tái)地區(qū)可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次為澳門,香港,臺(tái)北),還有新加坡:Asia/Singapore,當(dāng)然PRC也行。
轉(zhuǎn)載于:https://blog.51cto.com/nameyjj/661377
總結(jié)
以上是生活随笔為你收集整理的PHP Warning: date(): It is not safe to rely on the system's timezone settings的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iPhone 越狱
- 下一篇: 安全实现Linux网络监控(1)