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

当前回答

您可能需要将时区放在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)。

下面是支持的时区列表。

其他回答

@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

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

您可能需要将时区放在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)。

下面是支持的时区列表。

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

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

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

我在us-west-2(俄勒冈州)地区托管我的EC2和S3存储桶。当我调用$s3client->listBuckets()来列出我的php中现有的桶时,我得到了异常-“未捕获的异常'异常'与消息'DateTime::__construct():依赖系统的时区设置是不安全的…”。 我做了以下更改,使其工作。分享这些细节,以防有人面临类似的问题,以上任何答案都没有帮助。

Based on documentation @ AWS Configuring Network Time Protocol (NTP), I confirmed ntpd service status is fine by running ntpstat command. If you get error, this link helps you to know what is going wrong. Opened /etc/php.ini file (some may have it in different path based on version of php installed) and found that date.timezone was not set to any value and also it was commented by default. I un-commented by removing ';' before this line and set its value to "UTC" and saved the file. Restarted http and ntp daemons using sudo service httpd restart and sudo service ntpd restart commands.

在此之后,我能够成功地列出桶没有任何例外。希望这能有所帮助。

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

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