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

当前回答

这个问题一直困扰我一段时间,因为我试图注入一个“createbucket.php”脚本到作曲家,我一直被告知我的时区是不正确的。

最后,解决这个问题的唯一方法是: $ sudo nano /etc/php.ini

搜索时区

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = UTC

确保你移除;

最后

$ sudo service httpd restart

然后你就可以出发了:)

其他回答

解决这个问题有两种方法

首先,在php.ini文件中输入默认时区

date.timezone = "America/New_York"

在php.ini中设置好时区后,重新启动服务器

其次,改变运行时间 根据您的需要分配时区

date_default_timezone_set('America/New_York');

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

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

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

您可能需要将时区放在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)。

下面是支持的时区列表。

在我的特殊情况下,我有PHP配置为使用PHP- fpm (FastCGI进程管理器)。当从CLI执行phpinfo()时,我看到了我在php.ini中设置的正确时区,但在浏览器中仍然不正确,导致我的代码失败。我只需要在服务器上重新启动php-fpm服务。

service rh-php56-php-fpm restart

如果您编辑了php.ini,则可能还需要重新启动httpd服务

service httpd restart

如果你不能修改你的php.ini配置,你也可以在你的代码开头使用下面的代码片段:

date_default_timezone_set('Africa/Lagos');//or change to whatever timezone you want

时区列表可以在http://www.php.net/manual/en/timezones.php上找到。