What is default timezone in Yii2?
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' => [
// ...
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

Puttu
Updated on June 27, 2022Comments
-
Puttu 12 months
I have my local system timezone
Asia/Calcutta
but when I usedate_default_timezone_get()
function in Yii Framework it returns meUTC
.The same function returns me
Asia/Calcutta
when I use in mytest.php
file.What is the problem?
-
Puttu about 7 years@skypjack Thanks for making my question more clear.. !
-
-
RK12 over 3 yearsI 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.