您的位置:首页 > 编程语言 > PHP开发

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

2016-09-04 23:23 288 查看
从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了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: