php程序中报date错误
在寫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)?/span>PHP所取的時(shí)間是格林威治標(biāo)準(zhǔn)時(shí)間,所以和你當(dāng)?shù)氐臅r(shí)間會(huì)有出入格林威治標(biāo)準(zhǔn)時(shí)間和北京時(shí)間大概差8個(gè)小時(shí)左右,我們可以按照下面的方法解決:
1、在頁(yè)頭使用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即可!
總結(jié)
以上是生活随笔為你收集整理的php程序中报date错误的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。