跳到主要内容

CONVERT_TZ

描述

转换 datetime 值,从 from_tz 给定时区转到 to_tz 给定时区,并返回结果值。特殊情况:

  • 如果参数无效该函数返回 NULL。

语法

CONVERT_TZ(<dt>, <from_tz>, <to_tz>)

参数

参数说明
<dt>需要被转换的 datetime 值
<from_tz>dt 的原始时区
<to_tz>需要转换的时区

返回值

转换后的 datetime 值

示例

select CONVERT_TZ('2019-08-01 13:21:03', 'Asia/Shanghai', 'America/Los_Angeles');
+---------------------------------------------------------------------------+
| convert_tz('2019-08-01 13:21:03', 'Asia/Shanghai', 'America/Los_Angeles') |
+---------------------------------------------------------------------------+
| 2019-07-31 22:21:03 |
+---------------------------------------------------------------------------+
select CONVERT_TZ('2019-08-01 13:21:03', '+08:00', 'America/Los_Angeles');
+--------------------------------------------------------------------+
| convert_tz('2019-08-01 13:21:03', '+08:00', 'America/Los_Angeles') |
+--------------------------------------------------------------------+
| 2019-07-31 22:21:03 |
+--------------------------------------------------------------------+