Timezone for Formatter

To set the default timezone in YII, use the following code in your main config file:

  1. return [  
  2.   'timeZone' => 'America/Phoenix',
  3.  ]

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.

  1. return [  
  2.   'timeZone' => 'UTC',
  3.  ]

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’.

Published by

Joel Bowers

Web developer since 1999. PHP, YII2, Laravel, Javascript, HTML, CSS, jQuery, Perl, Wordpress, MySQL.

Leave a Reply

Your email address will not be published. Required fields are marked *