“date(): It is not safe to rely on the system'

2018-12-31 16:29发布

I got this error when I requested to update the PHP version from 5.2.17 to PHP 5.3.21 on the server.

<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 timezone
21条回答
低头抚发
2楼-- · 2018-12-31 16:58

If you cannot modify your php.ini configuration, you could as well use the following snippet at the beginning of your code:

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

The list of timezones can be found at http://www.php.net/manual/en/timezones.php.

查看更多
深知你不懂我心
3楼-- · 2018-12-31 16:59
<? print(gmdate("Y")); ?> 

instead of

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

worked for me (shows current year and no more shows the error message). (Thanks to Chris above)

查看更多
浅入江南
4楼-- · 2018-12-31 17:03

If you are using CodeIgniter and can't change php.ini, I added the following to the beginning of index.php:

date_default_timezone_set('GMT');
查看更多
梦醉为红颜
5楼-- · 2018-12-31 17:03

I had to put it in double quotes.

date_default_timezone_set("America/Los_Angeles"); // default time zone
查看更多
不再属于我。
6楼-- · 2018-12-31 17:03

You can set the timezone in your .htaccess file

php_value date.timezone UTC
查看更多
余生无你
7楼-- · 2018-12-31 17:04

This issue has been bugging me for SOME time as im trying to inject a "createbucket.php" script into composer and i keep being told my time-zone is incorrect.

In the end the only thing that fixed the issue was to: $ sudo nano /etc/php.ini

Search for timezone

[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

Ensure you remove the ;

Then finally

$ sudo service httpd restart

And you'll be good to go :)

查看更多
登录 后发表回答