Symfony2 和 date_default_timezone_get() - 依赖系统的时区设置是不安全的 [英] Symfony2 and date_default_timezone_get() - It is not safe to rely on the system's timezone settings
问题描述
我有一个 Symfony2 项目.我今天将我的 php 更新到 5.5.7,从那时起,我得到了
警告:date_default_timezone_get():依赖系统的时区设置是不安全的.您*需要*使用 date.timezone 设置或 date_default_timezone_set() 函数.如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是时区标识符拼错了.我们现在选择了时区UTC",但请设置 date.timezone 以选择您的时区.在...
我在 php.ini 中设置了默认时区
[日期];定义日期函数使用的默认时区;http://php.net/date.timezonedate.timezone = "欧洲/巴黎";
为了确保这是好的 php.ini,我正在检查
phpinfo();
我到达那里的路径是我正在修改的路径:
/usr/local/php5.5.7/lib
但在那里,我看到了
默认时区UTC
这很奇怪.
有什么想法吗?谢谢.
也许你想在 Apache 的 php.ini
中设置它,但你的 CLI(命令行界面)php.ini
不好.
使用以下命令找到您的 php.ini
文件:
php -i |grep php.ini
然后搜索date.timezone
并将其设置为"Europe/Amsterdam"
.所有有效时区都可以在这里找到http://php.net/manual/en/timezones.php>
另一种方法(如果其他方法不起作用),搜索文件 AppKernel.php
,它应该在您的 Symfony<的文件夹 app
下/em> 项目目录.覆盖AppKernel
类下面的__construct
函数:
I have a Symfony2 project. I updated my php to 5.5.7 today and since then, I am getting the
Warning: date_default_timezone_get(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in...
I setup the default timezone in my php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Paris";
To be sure that this is the good php.ini, I was checking with
phpinfo();
And the path I ma getting there is the one I am modifying:
/usr/local/php5.5.7/lib
But in there, I see the
Default timezone UTC
Which is strange.
any idea? Thank you.
Maybe you are trying to set it in Apache's php.ini
, but your CLI (Command Line Interface) php.ini
is not good.
Find your php.ini
file with the following command:
php -i | grep php.ini
And then search for date.timezone
and set it to "Europe/Amsterdam"
. all valid timezone will be found here http://php.net/manual/en/timezones.php
Another way (if the other does not work), search for the file AppKernel.php
, which should be under the folder app
of your Symfony project directory. Overwrite the __construct
function below in the class AppKernel
:
<?php
class AppKernel extends Kernel
{
// Other methods and variables
// Append this init function below
public function __construct($environment, $debug)
{
date_default_timezone_set( 'Europe/Paris' );
parent::__construct($environment, $debug);
}
}
这篇关于Symfony2 和 date_default_timezone_get() - 依赖系统的时区设置是不安全的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!