当我请求在服务器上将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('Europe/Istanbul'); ?>

对于php(或您的位置)。

其他回答

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

date_default_timezone_set('GMT');

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

date_default_timezone_set('Asia/Dhaka');

此处支持的时区列表

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

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

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

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

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