Skip to content

CONVERT_TZ()

函数说明

CONVERT_TZ() 函数用于将给定的日期时间从一个时区转换为另一个时区。如果参数无效,则函数将返回 NULL。

函数语法

> CONVERT_TZ(dt,from_tz,to_tz)

参数释义

参数 说明
dt 必要参数。要转换的给定日期时间。
from_tz 必要参数。当前时区的标识
to_tz 必要参数。新的时区的标识

示例

mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
+-------------------------------------------+
| convert_tz(2004-01-01 12:00:00, GMT, MET) |
+-------------------------------------------+
| 2004-01-01 13:00:00                       |
+-------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
+-------------------------------------------------+
| convert_tz(2004-01-01 12:00:00, +00:00, +10:00) |
+-------------------------------------------------+
| 2004-01-01 22:00:00                             |
+-------------------------------------------------+
1 row in set (0.01 sec)

mysql> select convert_tz('2023-12-31 10:28:00','+08:00', 'America/New_York') as dtime;
+---------------------+
| dtime               |
+---------------------+
| 2023-12-30 21:28:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select convert_tz(NULL,'-05:00', '+05:30') as dtime;
+-------+
| dtime |
+-------+
| NULL  |
+-------+
1 row in set (0.00 sec)