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,从那时起,我就获得了
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...
我在php.ini中设置了默认时区
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Paris";
为确保这是个不错的php.ini,我正在与
进行检查phpinfo();
我要到达的路径就是我正在修改的路径:
/usr/local/php5.5.7/lib
但是在那里,我看到了
Default timezone 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
下.在类AppKernel
中覆盖下面的__construct
函数:
<?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);
}
}
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屋!