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

当前回答

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

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

其他回答

如果你不能访问php.ini文件,在你的域或子目录的根目录下创建或编辑一个。htaccess文件,并添加这个(由cpanel生成):

<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>

<IfModule php5_module>
php_value date.timezone "America/New_York"
</IfModule>

<IfModule lsapi_module>
php_value date.timezone "America/New_York"
</IfModule>
<? print(gmdate("Y")); ?> 

而不是

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

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

当你纠正不兼容时,一个快速的解决方案是禁用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 );

这个问题一直困扰我一段时间,因为我试图注入一个“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

然后你就可以出发了:)

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