“date(): 依赖系统的时区设置是不安全的...”

2022-08-30 05:57:15

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

答案 1

您可能需要将时区放在文件的配置行中。在你的 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

以下是支持的时区列表


答案 2

如果您无法修改 php.ini 配置,您也可以在代码开头使用以下代码段:

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

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


推荐