简体   繁体   English

在Amazon RDS服务上将时区设置为UTC + 8

[英]Set the timezone to UTC + 8 at the Amazon RDS service

I have implemented a system in my internal server 我已经在内部服务器中实现了一个系统

When insert record there is a current date field which is the timestamp and by default is the current time. 插入记录时,当前日期字段是时间戳,默认情况下是当前时间。

It works fine on local server until recently I need to move the database to Amazon RDS, it is set UTC instead of UTC + 8. 直到最近我需要将数据库移至Amazon RDS为止,它在本地服务器上都可以正常工作,它设置为UTC而不是UTC + 8。

So , instead of changing every query in my models PHP , are there any more convenient way to adapt the changes? 因此,除了在我的模型PHP中更改每个查询之外,还有其他更便捷的方法来适应更改吗?

I am using codeigniter and after some searching , it suggest using procedure like this: 我正在使用codeigniter并进行一些搜索后,建议使用以下过程:

Amazon RDS - are there workarounds to change a database time zone in SQL Server? Amazon RDS-是否有变通办法来更改SQL Server中的数据库时区?

DELIMITER |
CREATE PROCEDURE mysql.init_connect_procedure () 
IF  NOT(POSITION(‘rdsadmin@’ IN user()) = 1) 
THEN SET SESSION time_zone = 'America/New_York';
END IF |
DELIMITER ;

The problem is it that need to be call everytime I run the query? 问题是每次我运行查询时都需要调用它吗? so that how to modify the codeigniter Model class to run that? 这样如何修改codeigniter Model类来运行它?

Thanks a lot. 非常感谢。

I work with codeigniter and I find that using the php date_default_timezone_set('') solved the problem for me. 我与codeigniter一起工作,我发现使用php date_default_timezone_set('')为我解决了这个问题。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM