简体   繁体   English

使用 PHPMyAdmin 为 MySQL 设置时区

[英]setting timezone for MySQL using PHPMyAdmin

Currently whenever a user creates a new account, I have a Creation_date column that has datatype timestamp .目前,每当用户创建新帐户时,我都有一个数据类型为timestamp的 Creation_date 列。 Currently this timestamp reads 3 hours ahead of EST (if it's 5PM in Boston it reads 8PM).目前这个时间戳比 EST 提前 3 小时读取(如果在波士顿是下午 5 点,则读取为晚上 8 点)。 Is there a way to change the timezone to EST?有没有办法将时区更改为 EST? What timezone is it set to currently?当前设置为哪个时区?

This has to do with MySQL's timezone. 这与MySQL的时区有关。

You can set it per connection (eg via PHPMyAdmin) with the following: 您可以使用以下方法为每个连接设置它(例如通过PHPMyAdmin):

SET time_zone = timezone;

However, this will reset if MySQL restarts. 但是,如果MySQL重新启动,它将重置 So it is better set at the server level. 因此最好在服务器级别进行设置。 Which, I assume, you can't. 我以为您不能。

I encourage you to read more from the MySQL Docs . 我鼓励您从MySQL文档中阅读更多内容。

因此与此问题

SET SESSION time_zone = '+8:00'

TIMESTAMP values are converted to UTC when inserted into the DB and converted back to the current timezone set in MySQL on retrieval. TIMESTAMP值插入数据库后会转换为UTC,并在检索时转换回MySQL中设置的当前时区。 The other answers show how to set the timezone in MySQL which will determine what value comes out of the database. 其他答案显示了如何在MySQL中设置时区,该时区将确定从数据库中输出什么值。

Another option is to use a DATETIME column, store ALL of your dates in UTC, and convert them to the desired timezone in your application (PHP or wherever you get the values from). 另一种选择是使用DATETIME列,将所有日期存储为UTC,然后将其转换为应用程序中所需的时区(PHP或从中获取值的任何地方)。

This is a COMPLETE example, for Argentina这是一个完整的例子,适用于阿根廷

SET GLOBAL time_zone = "-03:00";

you just need to change the "-03:00" for your timezone and run that command like a simple query, even in PhpMyAdmin.您只需要为您的时区更改“-03:00”并像简单查询一样运行该命令,即使在 PhpMyAdmin 中也是如此。

SET GLOBAL time_zone =时区;

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

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