天天看點

php程式中報date錯誤

在寫php程式中有時會出現這樣的警告:

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 。

這是因為PHP所取的時間是格林威治标準時間,是以和你當地的時間會有出入格林威治标準時間和中原標準時間大概差8個小時左右,我們可以按照下面的方法解決:

1、在頁頭使用date_default_timezone_set()設定我的預設時區為中原標準時間,即 <?php

date_default_timezone_set("PRC"); ?>就可以了。

2、在php.ini中設定date.timezone的值為PRC,設定好以後的為:date.timezone=PRC或者date.timezone = Asia/Shanghai,同時取消這一行代碼的注釋,即去掉前面的分号就可以了。

然後重新開機apache即可!