最新下载
热门教程
- 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 
PHP中date函数date(): It is not safe to rely
时间:2022-06-24 19:54:09 编辑:袖梨 来源:一聚教程网
在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
为什么会出现这样的报错?
从 PHP 5.1.0 引用了时区设置(date.timezone),但其默认又是关闭的,所以使用date()等函数时,都会产生E_NOTICE 或者 E_WARNING 信息。
处理方法1
在调用date前加入下代码
在页头加入代码:ate_default_timezone_set("PRC");
在页头加入代码:ini_set('date.timezone','注释:RPC');
在php.ini中启用date.timezone设置并设置其值:date.timezone=PRC,并重启apache;
注释:RPC代表中华人民共和国。
相关文章
- 洛克王国世界初始精灵哪个好-精灵御三家选择推荐 11-04
 - 逃离鸭科夫农场镇专家快递员1任务怎么做 专家快递员1任务流程 11-04
 - 逃离鸭科夫四骑士打法攻略 四骑士打法攻略(二) 11-04
 - 逃离鸭科夫农场镇晋升专家快递员怎么做 晋升专家快递员任务流程 11-04
 - 逃离鸭科夫农场镇进阶实力证明2怎么做 实力证明2任务流程 11-04
 - 逃离鸭科夫农场镇清理校园任务怎么完成 清理校园任务流程 11-04