当前位置: 移动技术网 > IT编程>开发语言>PHP > 深入解析PHP 5.3.x 的strtotime() 时区设定 警告信息修复

深入解析PHP 5.3.x 的strtotime() 时区设定 警告信息修复

2019年04月05日  | 移动技术网IT编程  | 我要评论

php warning:
strtotime(): 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 'asia/chongqing' for 'cst/8.0/no dst' instead in /var/www/cacti/index.php
查了一些资料,说是php版本太高,在新版本中必须指定timezone之类的。

具体操作方式如下:
1、在php配置文件中添加timezone的配置
(参照debian的配置规则,添加小的配置规则文件即可,好维护,自定义性好)
~# vim /etc/php/cli-php5.3/ext-active/date_timezone.ini
date.timezone = "asia/shanghai"
~ # env-update
~ # source /etc/profile
自定义的文件放在cli-php5.3/ext-active目录中,是因为php默认是采用cli方式,另外ext-active目录是表示启用特性的专用目录,这个可以从/etc/env.d/20php5.3文件中看出来
manpath="/usr/lib/php5.3/man/"
config_protect_mask="/etc/php/cli-php5.3/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/apache2-php5.3/ext-active/"

2、在出现错误提示的php文件中添加date_default_timezone_set('asia/shanghai');位置是在中国上海

注:
在某些参考资料中是说这两个方法任选其一就可,但经我测试,必须两个方法同时使用,才不会再出现错误提示。

经实测其实第二个方法并不需要在每个出现错误提示的php文件中添加,只需在其中一个php文件中添加即可。另外添加的时区不需要与提示中的时区一样,比如系统给我的提示是chongqing,但我设置成shanghai也是一样的,当然这个时间也是与我系统的时区设置是一样的。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网