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

来源:互联网 发布:mac fifa 编辑:程序博客网 时间:2024/06/10 22:43

从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了。

1 0
原创粉丝点击