在php程序开发中有时会出现类似于这样的警告:

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 ‘utc’ for ‘8.0/no dst’ instead in……

能这这警告的提示信息我们可以初步知道是时区问题,这是因为php默认获取的时间是格林威治标准时间,所以这个时间会和标准北京时间相差8个小时,对于这个错误我们可以选用下面两个方法之中的一个就可以解决。

1、在页头使用date_default_timezone_set('prc')设置时区为北京时间即可。

2、在服务器php配置文件 php.ini 中设置date.timezone的值为prc;找到date.timezone=prc,同时去掉前面的分号,即取消这一行代码的注释,如果没有此句可自行加上,然后重启web服务器即可。

关于php时间方面的知识可参考:php时间函数使用详解

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对www.887551.com的支持。如果你想了解更多相关内容请查看下面相关链接