使用 PHPMyAdmin 为 MySQL 设置时区

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11853534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:26:08  来源:igfitidea点击:

setting timezone for MySQL using PHPMyAdmin

mysqlphpmyadmin

提问by Mobie

Currently whenever a user creates a new account, I have a Creation_date column that has datatype timestamp. Currently this timestamp reads 3 hours ahead of EST (if it's 5PM in Boston it reads 8PM). Is there a way to change the timezone to EST? What timezone is it set to currently?

目前,每当用户创建新帐户时,我都会有一个具有数据类型的 Creation_date 列timestamp。目前,此时间戳比美国东部标准时间早 3 小时(如果在波士顿是下午 5 点,则为晚上 8 点)。有没有办法将时区更改为 EST?当前设置为哪个时区?

回答by Jason McCreary

This has to do with MySQL's timezone.

这与 MySQL 的时区有关。

You can set it per connection (e.g. via PHPMyAdmin) with the following:

您可以通过以下方式设置每个连接(例如通过 PHPMyAdmin):

SET time_zone = timezone;

However, this will resetif MySQL restarts. So it is better set at the server level. Which, I assume, you can't.

但是,如果 MySQL 重新启动,这将重置。所以最好设置在服务器级别。我想,你不能。

I encourage you to read more from the MySQL Docs.

我鼓励您从MySQL Docs 中阅读更多内容。

回答by Mihai Matei

Accordingly with this question

因此,这个问题

SET SESSION time_zone = '+8:00'

回答by drew010

TIMESTAMPvalues are converted to UTC when inserted into the DB and converted back to the current timezone set in MySQL on retrieval. The other answers show how to set the timezone in MySQL which will determine what value comes out of the database.

TIMESTAMP插入数据库时​​,值将转换为 UTC,并在检索时转换回 MySQL 中设置的当前时区。其他答案显示了如何在 MySQL 中设置时区,这将确定数据库中的值。

Another option is to use a DATETIMEcolumn, 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 或您从中获取值的任何地方)。

回答by Dev M

SET GLOBAL time_zone = timezone;

设置全局 time_zone = 时区;