关于PHP设置默认时区

今天查看phpinfo的时候突然发现了一个错误提示,内容如下

PHP Warning:  phpinfo(): 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.

解决方法就是修改php.ini的date.timezone配置项,下面就对这个配置想的参数做一下说明:

这个配置项,是指php获取时间时的时区,默认为注释状态,默认值为UTC,显示的时间都是格林威治标准时间,和北京时间差了正好8个小时,所以如果不进行配置,在使用php时,获取的时间不是北京或者当地时间。因此,一般在安装完php时会修改他的值为Asia/Chongqing (重庆),Asia/Shanghai (上海),Asia/Urumqi (乌鲁木齐),Asia/Macao (澳门),Asia/Hong_Kong (香港),Asia/Taipei (台北),PRC等

RPC的意思是People’s Republic of China,即代表中国。

但官方文档中并没有这样的参数,只有Asia/Shanghai、Asia/Hong_Kong等这些参数。

这个参数可以设置为RPC,php也能识别,但是还是设置为Asia/Shanghai要好一些吧。

设置完成后,记得重启apache服务

OK,问题解决