当我请求在服务器上将PHP版本从5.2.17更新到PHP 5.3.21时,我得到了这个错误。

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  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 'America/New_York' for 'EDT/-4.0/DST' instead</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 86</p>

</div>
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 'America/New_York' for 'EDT/-4.0/DST' instead in /filelocation right here/system/libraries/Log.php on line 86

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 'America/New_York' for 'EDT/-4.0/DST' instead in /filelocation right here/system/libraries/Log.php on line 99
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  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 'America/New_York' for 'EDT/-4.0/DST' instead</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 99</p>

</div>

当前回答

在你的连接页面中输入如下代码:date_default_timezone_set("Africa/Johannesburg");基于你当前的位置。

其他回答

您可能需要将时区放在php.ini文件的配置行中。你应该在你的php.ini文件中有一个这样的块:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

如果没有,添加它(用您的时区替换)。配置完成后,确保重新启动httpd (service httpd restart)。

下面是支持的时区列表。

我必须把它放在双引号里。

date_default_timezone_set("America/Los_Angeles"); // default time zone
<? print(gmdate("Y")); ?> 

而不是

<? print(date("Y")); ?>

为我工作过(显示当前年份,不再显示错误消息)。 (感谢上面的克里斯)

如果你正在使用CodeIgniter并且不能更改php.ini,我在index.php的开头添加了以下内容:

date_default_timezone_set('GMT');

上面来自CtrlX的答案是正确的答案,但它可能不完全有效。 我在php.ini文件中添加了这一行:

date.timezone = "America/Los_Angeles"

但它没有删除所有文件的PHP错误,因为我的一些PHP脚本在子文件夹中。所以我必须编辑.htaccess文件来设置php.ini以递归地使用(在子文件夹中):

suphp_configpath /home/account_name/public_html

其中account_name是你的cpanel帐户名,public_html是你的php.ini文件所在的文件夹。