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

当前回答

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

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

timezone.ini

    date.timezone=Australia/Sydney

其他回答

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

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

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

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

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

解决这个问题有两种方法

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

date.timezone = "America/New_York"

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

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

date_default_timezone_set('America/New_York');

如果这些都不是你的选择

修改php . ini。 添加date_default_timezone调用。

你可以用gmdate代替date。

当我需要一年的时间来获得一个版权片段时,我使用gmdate(“Y”)。

<? print(gmdate("Y")); ?> 

而不是

<? print(date("Y")); ?>

为我工作过(显示当前年份,不再显示错误消息)。 (感谢上面的克里斯)