我在php.ini文件中有这个条目:
date.timezone = 'Europe/London';
Run Code Online (Sandbox Code Playgroud)
但每次我在命令行脚本中使用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
Run Code Online (Sandbox Code Playgroud)
因此,我必须在任何脚本中执行以下操作才能使其工作:
date_default_timezone_set('Europe/London');
Run Code Online (Sandbox Code Playgroud)
还有什么可能导致此错误?
UPDATE
我在命令行和Web浏览器中使用了以下内容:
<?php
var_dump(ini_get('date.timezone'));
exit;
Run Code Online (Sandbox Code Playgroud)
在命令行中我得到:
string(0) ""
Run Code Online (Sandbox Code Playgroud)
在网络浏览器中,我得到:
string(13) "Europe/London"
Run Code Online (Sandbox Code Playgroud)
Kin*_*nch 21
CLI和webserver(以及cgi和fpm)使用不同的php.ini-files.因为你说你在浏览器中看到了正确的值,我猜你编辑错了.关于cli类型
php --ini
Run Code Online (Sandbox Code Playgroud)
要找出,你必须编辑的那个.例如,它是第二行中的那个
Loaded Configuration File: /etc/php5/cli/php.ini
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14624 次 |
| 最近记录: |