Warning: date() :It is not safe to rely on the system's timezone settings

在執行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 /usr/local/apache/htdocs/test.php on line 50 。php

Cause: 
   這是由於PHP所取的時間是格林威治標準時間,因此和你當地的時間會有出入格林威治標準時間和北京時間大概差8個小時左右,咱們能夠按照下面的方法解決。apache

解決辦法:ide

一、在頁頭使用date_default_timezone_set()設置個人默認時區爲北京時間,即ui

<?phpthis

date_default_timezone_set("PRC");get

?>就能夠了。io

二、在php.ini中設置date.timezone的值爲PRC,設置好之後的爲:date.timezone=PRC,同時取消這一行代碼的註釋,即去掉前面的分號就能夠了。function

相關文章
相關標籤/搜索