Timezone in symfony

10,402

Solution 1

try

add in app/AppKernel.php

 public function __construct($environment, $debug)
{
    date_default_timezone_set( 'Europe/Warsaw' );
    parent::__construct($environment, $debug);
}

I had the same problem with CI system , and that was solution

Solution 2

If your Symfony version is "^4.*" you can set your global timeZone in project/public/index.php

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); date_default_timezone_set( 'Europe/Moscow' ); $request = Request::createFromGlobals();

PHP supported timezone list below

https://www.php.net/manual/en/timezones.europe.php

Solution 3

Ubuntu

Though I had date.timezone set in the /etc/php5/apache2/php.ini file.

I had to Set the date.timezone = "Asia/Calcutta" in the php.ini file which was in the cli directory.

/etc/php5/cli/php.ini

This solved it for me...

Share:
10,402

Related videos on Youtube

aggie29
Author by

aggie29

Updated on June 04, 2022

Comments

  • aggie29
    aggie29 almost 2 years

    I'm trying to run new symfony project by symfony new name_project 2.7.21. Unfortunately, I keep having the error for incorrect time zone. I changed it in my C:\xampp\php\php.ini file. Do I have to change it somewhere else? Many thanks for your help

  • aggie29
    aggie29 over 7 years
    I'm not sure if I understand, I'm quite new to this. To which appKernel shall I add it. I thought appKernel is created once I create symfony project but I cannot because of the timezone problem.
  • Michał G
    Michał G over 7 years
    problem you described tells that there is a problem with timezone configuration on your server . Simple way (witchout messing in server configuration) is to add above code in AppKernel - that code overwrite wrong configuration setting. And yes you need to add it in appkernel that was created when you created symfony project. (you don't edit appkernel from browser , you need to tu use text/code editor)
  • aggie29
    aggie29 over 7 years
    I think I'm getting closer but it still doesn't work. I changed it by nano editor and I added this function to appKernel... any other ideas?
  • aggie29
    aggie29 over 7 years
    date.timezone setting must be set. Set the date.timezone setting in php.ini (like Europe/Paris) . I also made a check and it says the times match <?php phpinfo(); date_default_timezone_set('Europe/Amsterdam'); $script_tz = date_default_timezone_get(); if (strcmp($script_tz, ini_get('date.timezone'))){ echo 'Script timezone differs from ini-set timezone.'; } else { echo 'Script timezone and ini-set timezone match.'; } ?>