解决php的“It is not safe to rely on the system’s timezone settings”问题

1.前几天换个服务器,重新部署了PHP环境,访问首页底部时候,strtotime():报错

解决php的“It is not safe to rely on the system’s timezone settings”问题_第1张图片

2.根据提示找到文件,定位到错误行。


翻了翻PHP手册,发现是时区设置不正确造成的。从PHP 5.1.0开始当对使用date()等函数时,如果timezone设置不正确,在每一次调用时间函数时,都会产生E_NOTICE 或者 E_WARNING 信息,而又在php中,date.timezone这个选项,默认情况下是关闭的,无论用什么php命令都是格林威治标准时间,但是PHP5.3中如果没有设置部分时间类函数也会强行抛出了这个错误的。

3.解决方案

在需要用到这些时间函数的时候,在页面头部添加date_default_timezone_set("PRC");

解决php的“It is not safe to rely on the system’s timezone settings”问题_第2张图片

                                            刷新再来看看,OK,页面恢复正常了。

解决php的“It is not safe to rely on the system’s timezone settings”问题_第3张图片

你可能感兴趣的:(解决php的“It is not safe to rely on the system’s timezone settings”问题)