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

品味人生 • 发布于 2019-02-01 21:37:02

这个家伙很害羞,不想介绍自己!

最近发现PHP错误日志体积巨大。仔细观察发现,这个文件以秒为单位在增加,说明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:www.frontopen.combbbxxx.php on line 21

在百度爬文了许久,发现是由于PHP 5.3中需要设置时区,仔细查阅找到三种解决办法:

一、在页头使用date_default_timezone_set()设置 date_default_timezone_set('PRC');

二、在页头使用ini_set('date.timezone','Asia/Shanghai');

三、修改php.ini配置文件。打开php.ini文件查找;date.timezone = 去掉前面的分号修改成为:date.timezone =PRC

上面的三种设置主要是针对中国大陆的情况来设置,同时PRC也可以用Asia/Shanghai,Asia/Chongqing,Asia/Urumqi来代替。