在Yii中设置默认时区 [英] Set default timezone in Yii

查看:210
本文介绍了在Yii中设置默认时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 config.php

中使用以下配置为时区:

 'timeZone'=> ; 'UTC',

它工作正常,所有日期根据 UTC存储在数据库中。现在每个用户在他/她的个人资料中都有自己的时区,如 UTC + 5 UTC-5 UTC + 0 等。 p>

现在,如何根据用户时区在报表中显示日期。我使用活动记录从数据库中获取记录。有没有一般的方式,所有的查询,或者我们必须转换日期到用户时区每次手动php?



谢谢。

解决方案

您可以在Yii中设置Timezone,方法是在配置文件的main.php文件中添加以下值:

 返回数组(
'timeZone'=>'亚洲/加尔各答',

对于PHP中的时区列表: http:// php。 net / manual / en / timezones.php


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

这篇关于在Yii中设置默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆