[英]Timezone: Mysql save UTC and PHP read America/Sao_Paulo
I would like to save at mysql in UTC timezone and read with PHP using America/Sao_Paulo timezone. 我想保存在UTC时区的mysql中,并使用America / Sao_Paulo时区与PHP一起阅读。
Im using YII framework. 我正在使用YII框架。 Its not working property, how could I do that?
它不起作用,我该怎么办?
main.php: main.php:
'timezone' => 'America/Sao_Paulo',
'db'=>array(
...
'initSQLs'=>array("SET time_zone = '+00:00'"),
...
)
Try this on your mysql console or gui: 在您的mysql控制台或gui上尝试一下:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Then use again: 然后再次使用:
SET time_zone='America/Sao_Paulo';
You also can change by this: 您还可以通过以下方式进行更改:
SET time_zone = 'Brazil/West';
Source: http://blog.will.eti.br/2013/mysql-unknown-or-incorrect-time-zone-americasao_paulo/ 资料来源: http : //blog.will.eti.br/2013/mysql-unknown-or-incorrect-time-zone-americasao_paulo/
Do this in your PHP code: 在您的PHP代码中执行此操作:
date_default_timezone_set('UTC');
Now PHP operates in UTC. 现在,PHP在UTC中运行。 It's up to you to convert to user local times but you have a common ground.
由您决定转换为本地用户时间,但是您有共同点。
And in MySQL use UTC_TIMESTAMP()
for your DATETIME
needs. 在MySQL中,根据您的
DATETIME
需求使用UTC_TIMESTAMP()
。 It uses UTC time regardless of the MySQL settings so you don't need to worry anymore. 无论MySQL设置如何,它都使用UTC时间,因此您无需担心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.