What is default timezone in Yii2?

16,076

Solution 1

Check the documentation:

http://www.yiiframework.com/doc-2.0/yii-base-application.html#getTimeZone%28%29-detail

It explains that "If time zone is not configured in php.ini or application config, it will be set to UTC by default."

Solution 2

For Yii 2, If time zone is not configured in php.ini or application config, it will be set to UTC by default, as yii\base\Application:

if (isset($config['timeZone'])) {
    $this->setTimeZone($config['timeZone']);
    unset($config['timeZone']);
} elseif (!ini_get('date.timezone')) {
    $this->setTimeZone('UTC');
}

How to set timezone for Yii 2

You could set default timezone for Yii2 application in config:

$config = [
    'timeZone' => 'Asia/Calcutta',
    'components' => [
    // ...

Yii2 Applications > timeZone

Solution 3

date_default_timezone_get() 

is a php built-in function. yii2 sets the the timezone to the timezone setted in the config. Raw php does NOT so the default timezone of the server is being fetched

Share:
16,076
Puttu
Author by

Puttu

Updated on June 27, 2022

Comments

  • Puttu
    Puttu almost 2 years

    I have my local system timezone Asia/Calcutta but when I use date_default_timezone_get() function in Yii Framework it returns me UTC.

    The same function returns me Asia/Calcutta when I use in my test.php file.

    What is the problem?

    • Puttu
      Puttu about 8 years
      @skypjack Thanks for making my question more clear.. !
  • RK12
    RK12 over 4 years
    I am using timeZone' => 'UTC', in my config and when i print echo date_default_timezone_get(); in frontend index file It gives me Asia/Calcutta.