To set the default timezone in YII, use the following code in your main config file:
- return [
- 'timeZone' => 'America/Phoenix',
- ]
However, take note that YII assumes the datetime in the database is UTC. So, if you are inserting the data in the database already adjusted to current timezone, YII will adjust it again and it will be off.
One option is to set the YII timezone to UTC so that it does not adjust the time.
- return [
- 'timeZone' => 'UTC',
- ]
So now you set the default time zone, yet your GridView and DetailView don’t show in the updated time zone. Simple fix. Set the format of the item to datetime. So like ‘last_viewed:datetime’.