PHP 5.x.x 使用date()出现警告问题

从PHP 5.x.x 开始,当使用date()等函数时,如果timezone设置未指定,在每一次调用时间函数时,都会产生warning信息如下:

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 the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\AppServ\www\demo\01\003\index.php on line 2
2016-09-04:09:03

这是因为没有指定时区造成的(细心观察可以看到打出来的时间也是不对的),我们可以通过warning上说的两种方法进行设置。不过感觉都比较麻烦,最简单的是打开php.ini文件,然后找到“; date.timezone”这一行,然后将其修改为“date.timezone = “Asia/Shanghai””,最后重新启动apache服务即可。
这样我们就永久的指定了时区为上海,不会再报warning了。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值