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

更新

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

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

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


当前回答

简单的 选择@@system_time_zone;

返回PST(或与您的系统相关的任何值)。

如果你试图确定会话时区,你可以使用这个查询: 选择如果(@@session。time_zone = 'SYSTEM', @@system_time_zone, @@session.time_zone);

如果会话时区与系统时区不同,将返回会话时区。

其他回答

要根据您的时区获取当前时间,您可以使用以下命令(在我的示例中是'+5:30')

选择DATE_FORMAT (convert_tz(现在(),@@session.time_zone, ' + 05:30 '), Y % - % - % d ')

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

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

要获取mysql的当前时区,你可以做以下事情:

 SELECT @@system_time_zone;   # from this you can get the system timezone 
 SELECT IF(@@session.time_zone = 'SYSTEM', @@system_time_zone, @@session.time_zone) # This will give you time zone if system timezone is different from global timezone

现在如果你想改变mysql时区,那么:

 SET GLOBAL time_zone = '+00:00';   # this will set mysql timezone in UTC
 SET @@session.time_zone = "+00:00";  # by this you can chnage the timezone only for your particular session 

任何人来查找mysql数据库的时区。

通过这个查询,你可以得到当前的时区:

mysql> SELECT @@system_time_zone as tz;
+-------+
|  tz   |
+-------+
|  CET  |
+-------+

简单的 选择@@system_time_zone;

返回PST(或与您的系统相关的任何值)。

如果你试图确定会话时区,你可以使用这个查询: 选择如果(@@session。time_zone = 'SYSTEM', @@system_time_zone, @@session.time_zone);

如果会话时区与系统时区不同,将返回会话时区。