PHP中date函数date(): It is not safe to rely

九月 15, 2019 | views
Comments 0

今天在php直接使用date函数会发现提示date():It is not safe to rely...错误了,提示是不是一个安全的用法,那么要如何解决此问题呢.

在PHP代码中调用date函数时,在日志里看到如下报错:

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//phpfensi.com

为什么会出现这样的报错?

从 PHP 5.1.0 引用了时区设置(date.timezone),但其默认又是关闭的,所以使用date()等函数时,都会产生E_NOTICE 或者 E_WARNING 信息.

处理方法,在调用date前加入下代码:

在页头加入代码:ate_default_timezone_set("PRC");

在页头加入代码:ini_set('date.timezone','注释:RPC');

在php.ini中启用date.timezone设置并设置其值,date.timezone=PRC,并重启apache.



zend