有人知道MySQL中有没有这样的函数吗?

更新

这不会输出任何有效的信息:

mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+

或者MySQL本身不能确切地知道所使用的time_zone,这很好,我们可以在这里涉及PHP,只要我能得到有效的信息,而不是像SYSTEM…


当前回答

你可以尝试以下方法:

select sec_to_time(TIME_TO_SEC( curtime()) + 48000);

在这里,您可以将时差指定为秒

其他回答

将一个虚拟记录插入到具有时间戳的数据库中 选择该记录并获取时间戳的值。 删除该记录。获取服务器写入数据时使用的时区,忽略PHP时区。

下面的查询返回当前会话的时区。

select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00'));

你只需要在修改系统时区后重新启动mysqld ..

MySQL的Global timezone取System的timezone。当你改变任何这样的系统属性,你只需要重新启动Mysqld。

如果需要将GMT差值作为整数:

SELECT EXTRACT(HOUR FROM (TIMEDIFF(NOW(), UTC_TIMESTAMP))) AS `timezone`

Use LPAD(TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),’%H:%i’),6,’+') to get a value in MySQL's timezone format that you can conveniently use with CONVERT_TZ(). Note that the timezone offset you get is only valid at the moment in time where the expression is evaluated since the offset may change over time if you have daylight savings time. Yet the expression is useful together with NOW() to store the offset with the local time, which disambiguates what NOW() yields. (In DST timezones, NOW() jumps back one hour once a year, thus has some duplicate values for distinct points in time).