MySQL CONVERT_TZ 函数

  • 定义和用法

    CONVERT_TZ - 时区转换。
  • 语法

    CONVERT_TZ(dt,from_tz,to_tz)
    这会将datetime值dt从from_tz给定的时区转换为to_tz给定的时区,并返回结果值。 如果参数无效,则此函数返回NULL。
  • 示例

    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.00 sec)
    
    尝试一下