Symfony2 and date_default_timezone_get() - It is not safe to rely on the system's timezone settings

前端 未结 7 1623
旧时难觅i
旧时难觅i 2020-11-27 12:43

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          


        
相关标签:
7条回答
  • 2020-11-27 13:22

    Since PHP 5.5, there is a separate php.ini file for CLI interface. If You use symfony console from command line, then this specific php.ini is used.

    In Ubuntu 13.10 check file:

    /etc/php5/cli/php.ini

    0 讨论(0)
  • 2020-11-27 13:31

    The current accepted answer by crack is deprecated in Symfony 2.3 and will be removed by 3.0. It should be moved to the constructor:

    public function __construct($environment, $debug) {
        date_default_timezone_set('Europe/Warsaw');
        parent::__construct($environment, $debug);
    }
    
    0 讨论(0)
  • 2020-11-27 13:34

    Found a similar way to fix this issue (at least it did for me).

    1. First check where the CLI php.ini is located:

      php -i | grep "php.ini"

    2. In my case I ended up with : Configuration File (php.ini) Path => /etc

    3. Then cd .. all the way back and cd into /etc, do ls in my case php.ini didn't show up, only a php.ini.default

    4. Now, copy the php.ini.default file named as php.ini:

      sudo cp php.ini.default php.ini

    5. In order to edit, change the permissions of the file:

      sudo chmod ug+w php.ini

      sudo chgrp staff php.ini

    6. Open directory and edit the php.ini file:

      open .

      Tip: If you are not able to edit the php.ini due to some permissions issue then copy 'php.ini.default' and paste it on your desktop and rename it to 'php.ini' then open it and edit it following step 7. Then move (copy+paste) it in /etc folder. Issue will be resolved.

    7. Search for [Date] and make sure the following line is in the correct format:

      date.timezone = "Europe/Amsterdam"

    I hope this could help you out.

    0 讨论(0)
  • 2020-11-27 13:35

    The problem appear when we are using PHP 5.1 on Redhat or Cent OS

    PHP 5.1 on RHEL/CentOS doesn't support the timezone functions

    0 讨论(0)
  • 2020-11-27 13:36

    add this code to Your AppKernel Class:

    public function init()
    {
        date_default_timezone_set('Asia/Tehran');
        parent::init();
    }
    
    0 讨论(0)
  • 2020-11-27 13:41

    Following up on sas's answer, PHP 5.4, Symfony 2.8, I had to use

    ini_set('date.timezone','<whatever timezone string>');
    

    instead of date_default_timezone_set. I also added a call to ini_set to the top of a custom web/config.php to get that check to succeed.

    0 讨论(0)
提交回复
热议问题