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

当前回答

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

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

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

其他回答

我有这个错误运行php-fpm在chroot监狱。我试着在chroot目录中创建etc/php.ini和/usr/share/zoneinfo,但它就是不工作。我甚至试着整理php-fpm守护进程,看看它们丢失了什么文件——什么都没有跳出来。

所以如果谷歌把你带到这里,因为你在使用配置为chroot的php-fpm时得到了这个错误,你可能可以通过在ENV部分的/etc/php-fpm.d/www.conf中添加这一行来修复它:

env[TZ] = America/New_York

通常需要重新启动php-fpm才能生效。希望这能帮助到一些人。

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

date_default_timezone_set('GMT');

这个问题一直困扰我一段时间,因为我试图注入一个“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配置为使用PHP- fpm (FastCGI进程管理器)。当从CLI执行phpinfo()时,我看到了我在php.ini中设置的正确时区,但在浏览器中仍然不正确,导致我的代码失败。我只需要在服务器上重新启动php-fpm服务。

service rh-php56-php-fpm restart

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

service httpd restart

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

date_default_timezone_set("America/Los_Angeles"); // default time zone