Symfony2和date_default_timezone_get()-依靠系统的时区设置并不安全 [英] Symfony2 and date_default_timezone_get() - It is not safe to rely on the system's timezone settings

查看:119
本文介绍了Symfony2和date_default_timezone_get()-依靠系统的时区设置并不安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆