|
在寫php程序中有時會出現(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)?a href=/itjie/phpjishu/ target=_blank class=infotextkey>php所取的時間是格林威治標(biāo)準(zhǔn)時間,所以和你當(dāng)?shù)氐臅r間會有出入格林威治標(biāo)準(zhǔn)時間和北京時間大概差8個小時左右,我們可以按照下面的方法解決:
1、在頁頭使用date_default_timezone_set()設(shè)置我的默認(rèn)時區(qū)為北京時間,即 <?php date_default_timezone_set("PRC"); ?>就可以了。
2、在php.ini中設(shè)置date.timezone的值為PRC,設(shè)置好以后的為:date.timezone=PRC或者date.timezone = Asia/Shanghai,同時取消這一行代碼的注釋,即去掉前面的分號就可以了。
然后重啟apache即可!
php技術(shù):關(guān)于php程序報date()警告的處理(date_default_timezone_set),轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。