PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* t

harbor1981發表於2016-03-23

[Wed Mar 23 17:20:56 2016] [error] [client 10.30.8.40] 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 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /opt/uploads/discuz2.5/app/post_list.php on line 31


這是因為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即可!


相關文章