当我请求在服务器上将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并且不能更改php.ini,我在index.php的开头添加了以下内容:

date_default_timezone_set('GMT');

其他回答

一个简单的方法,两个时区。

<?php 
$date = new DateTime("2012-07-05 16:43:21", new DateTimeZone('Europe/Paris')); 

date_default_timezone_set('America/New_York'); 

echo date("Y-m-d h:iA", $date->format('U')); 

// 2012-07-05 10:43AM 
?>

@Justis给我指出了正确的方向,但他的代码对我不起作用。这是:

// set the default timezone if not set at php.ini
if (!date_default_timezone_get('date.timezone')) {
    // insert here the default timezone
    date_default_timezone_set('America/New_York');
}

文档:http://www.php.net/manual/en/function.date-default-timezone-get.php

此解决方案不仅适用于那些没有完全系统访问权限的人。当您将脚本提供给除您之外的任何人时,它对于任何脚本都是必要的。当您将脚本分发给其他人时,您永远不知道该脚本将在哪个服务器上运行。

除了设定日期。Timezone =正如在几个答案中提到的, 我在php.ini文件中发现了一个错误,它阻止它到达date.timezone。 我找到它的方法是在终端的命令行中运行php。 这导致在第114行报告一个错误。在我的例子中,我取消了显示两个值之间有“|”的错误的设置。它不喜欢这样。 我删除了其中一个值和|,之后一切都很好

对于docker用户: 在你的项目中创建一个本地时区。ini文件,在docker-compose.yml中设置配置,

    volumes:
        - "./docker/config/timezone.ini:/usr/local/etc/php/conf.d/timezone.ini"

timezone.ini

    date.timezone=Australia/Sydney

当你纠正不兼容时,一个快速的解决方案是禁用index.php文件中的错误报告:

将下面的行插入到你的index.php下面define(' _JEXEC ', 1);

error_reporting( E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR |
E_COMPILE_WARNING );