首页 >后端开发 >php教程 >php提示PHP Warning: date(): It is not safe to rely on the......安全错误的解决办法

php提示PHP Warning: date(): It is not safe to rely on the......安全错误的解决办法

WBOY
WBOY原创
2016-06-20 13:04:33998浏览

php提示PHP Warning: date(): It is not safe to rely on the......安全错误的解决办法

在使用国外主机或者自己安装的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......

或者

PHP Warning: strtotime(): 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......

等时区安全警告提示问题。

这是因为PHP默认获取的时间是格林威治标准时间,所以这个时间会和标准北京时间相差8个小时,对此我们可以用如下办法解决:

1、在页头使用date_default_timezone_set('PRC')设置时区为北京时间即可。

2、在服务器配置文件 php.ini 中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC,同时去掉前面的分号,即取消这一行代码的注释。

提示:date_timezone_set — 别名 DateTime::setTimezone()


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn