当我请求在服务器上将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>

当前回答

我总是在codeigniter的根index.php中保留这一行,这样我的代码可以在任何服务器上工作

date_default_timezone_set('Asia/Dhaka');

此处支持的时区列表

其他回答

在index.php文件中添加以下内容。当我把我的应用程序从XAMPP服务器迁移到Apache 2.2和PHP 5.4时,我第一次遇到了这个问题……

我建议你在index.php文件中,而不是在php.ini文件中。

if( ! ini_get('date.timezone') )
{
    date_default_timezone_set('GMT');
}

在你的连接页面中输入如下代码: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)。

下面是支持的时区列表。

如果你使用Plesk,试试它,首先,打开PHP设置,在页面底部,更改日期。从DEFAULT到UTC的时区。

上面来自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文件所在的文件夹。