關(guān)于php程序報(bào)date()警告的處理(date_default_timezone_set)
在寫php程序中有時(shí)會(huì)出現(xiàn)這樣的警告:
PHP Warning: 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 D:\PHPWEB ews\file.php on line 17 。
這是因?yàn)镻HP所取的時(shí)間是格林威治標(biāo)準(zhǔn)時(shí)間,所以和你當(dāng)?shù)氐臅r(shí)間會(huì)有出入格林威治標(biāo)準(zhǔn)時(shí)間和北京時(shí)間大概差8個(gè)小時(shí)左右,我們可以按照下面的方法解決:
1、在頁頭使用date_default_timezone_set()設(shè)置我的默認(rèn)時(shí)區(qū)為北京時(shí)間,即 <?php date_default_timezone_set("PRC"); ?>就可以了。
2、在php.ini中設(shè)置date.timezone的值為PRC,設(shè)置好以后的為:date.timezone=PRC或者date.timezone = Asia/Shanghai,同時(shí)取消這一行代碼的注釋,即去掉前面的分號(hào)就可以了。
然后重啟apache即可!
- PHP如何通過date() 函數(shù)格式化顯示時(shí)間
- PHP date()格式MySQL中插入datetime方法
- PHP格式化顯示時(shí)間date()函數(shù)代碼
- js模仿php中strtotime()與date()函數(shù)實(shí)現(xiàn)方法
- PHP date()函數(shù)警告: It is not safe to rely on the system解決方法
- PHP中time(),date(),mktime()區(qū)別介紹
- PHP函數(shù)之日期時(shí)間函數(shù)date()使用詳解
- PHP格式化顯示時(shí)間date()函數(shù)案例講解
相關(guān)文章
thinkphp 一個(gè)頁面使用2次分頁的實(shí)現(xiàn)方法
thinkphp內(nèi)置ORG.Util.Page方法分頁,使分頁變得非常簡單快捷。 但是如果一個(gè)頁面里需要使用2次分頁,就會(huì)產(chǎn)生沖突,這里先記錄下百度來的解決辦法。需要的朋友可以參考下2013-07-07windows平臺(tái)中配置nginx+php環(huán)境
相對(duì)于linux來說,windows配置web環(huán)境不管是一鍵安裝包還是獨(dú)立配置簡單多了,這次是講以NGINX作為web的本地的測(cè)試環(huán)境。2015-12-12php數(shù)據(jù)結(jié)構(gòu)與算法(PHP描述) 查找與二分法查找
php數(shù)據(jù)結(jié)構(gòu)與算法(PHP描述) 查找與二分法查找,需要的朋友可以參考下2012-06-06