MySql-UTC格式的SELECT时间戳列 [英] MySql - SELECT TimeStamp Column in UTC format

查看:137
本文介绍了MySql-UTC格式的SELECT时间戳列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mysql 5.0 DB中,我有一列来控制LastUpdated信息.列是一个时间戳记,MySql自动更新数据.

In my Mysql 5.0 DB I have a column to control LastUpdated information. The Column is a TimeStamp one and MySql automatic updates data.

我正在尝试以UTC格式选择此列.

I'm trying to select this column in UTC format.

问题在于服务器已设置为美国日期时间.根据MySql文档,数据库将信息存储在UTC中,但是当我想显示信息时,它将其转换为服务器的时间.

The problem is that the server is setup to US datetime. According to MySql documentation, the DB stores the information in UTC but when I want to display information, it converts it to Server's time.

有什么方法可以执行SELECT命令来避免这种转换吗?

Is there any way to do SELECT command avoiding this convertion?

推荐答案

除了更改服务器的默认时区外,还可以通过执行以下SQL语句为每个连接调整时区:

Besides changing the default timezone of the server, the timezone can also be adjusted per connection by executing this SQL statement:

SET time_zone = timezone;

其中时区是时区的名称(请参见MySQL文档).

Where timezone is the name of the timezone (see MySQL docs).

或者,您也可以使用

Alternatively, you can also convert a timestamp to a different timezone using the CONVERT_TZ function.

这篇关于MySql-UTC格式的SELECT时间戳列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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