I am using following config for timezone in config.php
'timeZone' => 'UTC',
It is working fine and all dates are stored in database according to UTC. Now each user has its own timezone in his/her profile like UTC+5, UTC-5, UTC+0, etc.
Now how can I show dates in reports according to user timezone. I used active record to fetch records from database. Is there any general way for all queries or we have to convert date to user timezone each time manually in php ??
Thanks.
You can set Timezone in Yii by adding below value in main.php file of config
return array(
'timeZone' => 'Asia/Kolkata',
)
For time zone list in PHP : http://php.net/manual/en/timezones.php
You can use afterFind to change the time accordingly
public function afterFind()
{
//apply your logic here
$zone = Yii:app()->timeZone;
// I don't know code to change time zone, so I assume there is a function named "functionToChangeTimeZone"
$this->time = functionToChangeTimeZone($this->time , $zone);
return parent::afterFind();
}
now every record will have there time zone changed according their settings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With