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

当前回答

我在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.

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

其他回答

我有这个错误运行php-fpm在chroot监狱。我试着在chroot目录中创建etc/php.ini和/usr/share/zoneinfo,但它就是不工作。我甚至试着整理php-fpm守护进程,看看它们丢失了什么文件——什么都没有跳出来。

所以如果谷歌把你带到这里,因为你在使用配置为chroot的php-fpm时得到了这个错误,你可能可以通过在ENV部分的/etc/php-fpm.d/www.conf中添加这一行来修复它:

env[TZ] = America/New_York

通常需要重新启动php-fpm才能生效。希望这能帮助到一些人。

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

<?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 
?>
<? date_default_timezone_set('Europe/Istanbul'); ?>

对于php(或您的位置)。

在我的特殊情况下,我有PHP配置为使用PHP- fpm (FastCGI进程管理器)。当从CLI执行phpinfo()时,我看到了我在php.ini中设置的正确时区,但在浏览器中仍然不正确,导致我的代码失败。我只需要在服务器上重新启动php-fpm服务。

service rh-php56-php-fpm restart

如果您编辑了php.ini,则可能还需要重新启动httpd服务

service httpd restart

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

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