我的 php.ini 文件中有此条目:
date.timezone = 'Europe/London';
但每次我在命令行脚本中使用 DateTime() 时,我仍然会收到以下错误:
Exception: DateTime::__construct(): 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 'Europe/London' for 'BST/1.0/DST' instead
因此,我必须在任何脚本中执行以下操作才能使其正常工作:
date_default_timezone_set('Europe/London');
还有什么可能导致此错误?
UPDATE
我在命令行和网络浏览器中使用了以下命令:
<?php
var_dump(ini_get('date.timezone'));
exit;
在命令行中我得到:
string(0) ""
在网络浏览器中我得到:
string(13) "Europe/London"
CLI 和 Web 服务器(以及 cgi 和 fpm)使用不同的php.ini
- 文件。因为你说你在浏览器中看到了正确的值,所以我猜你编辑了错误的值。在 cli 类型上
php --ini
要找出答案,您必须编辑哪一个。例如,这是第二行中的一个
Loaded Configuration File: /etc/php5/cli/php.ini
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)