教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP警告date(): It is not safe to rely on the system

PHP警告date(): It is not safe to rely on the system

发布时间:2018-12-20   编辑:jiaochengji.com
教程集为您提供PHP警告date(): It is not safe to rely on the system等资源,欢迎您收藏本站,我们将为您提供最新的PHP警告date(): It is not safe to rely on the system资源
在用PHP5.3以上的PHP版本时,只要是涉及时间的会报一个Warning: date(): It is not safe to rely on the system\'s timezone settings.

大体是说timezone没有设置,在中国使用的是格林 8小时,所以需要设置一下。

第一种

在页面头部加入以下语句

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6596')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6596>

 date_default_timezone_set("PRC");  或 ini_set('date.timezone','asiashanghai');


这种方法有个缺点,就是所有的页面都得添加

第二种

在php.ini里找到date.timezone这行,把值改成PRC,如

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3770')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3770>

date.timezone = PRC。

如果没有这一行直接加上就好。最后重启WEB服务器与PHP即可。

友情提示:实际上,从 PHP 5.1.0 ,当对使用date()等函数时,如果timezone设置不正确,在每一次调用时间函数时,都会产生E_NOTICE 或者 E_WARNING 信息。而又在php5.1.0中,date.timezone这个选项,默认情况下是关闭的,无论用什么php命令都是格林威治标准时间,但是PHP5.3中好像如果没有设置也会强行抛出了这个错误的,解决此问题,只要本地化一下,就行了。

您可能感兴趣的文章:
PHP date()函数It is not safe to rely on the system s timezone settings
PHP Warning: date(): It is not safe to rely on the system
PHP警告date(): It is not safe to rely on the system
PHP5.3以上版本涉及时间的会报错 It is not safe to rely on the system's timezone settings.
A Study of WebRTC Security
php Date()函数输出中文年月日时分秒
php date()时间函数报错,时区问题解决 UTC PRC CST
PHP中设置时区方法总结
IOCP Thread Pooling in C
jQuery 开发者应该注意的9个错误

[关闭]
~ ~