Heim  >  Artikel  >  Backend-Entwicklung  >  深入解析PHP 5.3.x 的strtotime() 时区设定 警告信息修复_PHP教程

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

WBOY
WBOYOriginal
2016-07-21 15:00:20973Durchsuche

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也是一样的,当然这个时间也是与我系统的时区设置是一样的。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/328081.htmlTechArticlePHP 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....
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn