更新时间:2026-07-03 GMT+08:00
分享

from_utc_timestamp

from_utc_timestamp函数用于计算将UTC的时间戳转化为timezone所对应的本地时间戳。

命令格式

from_utc_timestamp(string timestamp, string timezone)

参数说明

表1 参数说明

参数

是否必选

参数类型

说明

timestamp

DATE、TIMESTAMP或STRING

UTC时间戳。

格式:

yyyy-MM-dd

yyyy-MM-dd HH:mm:ss

yyyy-MM-dd HH:mm:ss.SSS。

timezone

STRING

代表需要转换的目标时区。

返回值说明

返回TIMESTAMP类型的时间戳。

  • timestamp非DATE、TIMESTAMP或STRING类型时,返回报错,错误信息:data type mismatch;
  • timestamp为DATE、TIMESTAMP或STRING类型时,但不符合日期值的入参格式时,返回NULL;
  • timestamp值为NULL时,返回NULL。
  • timezone值为NULL时,返回NULL。

示例代码

返回1691978400000(代表2023-08-14 10:00:00)。

select from_utc_timestamp('2023-08-14 17:00:00','PST');

返回1691917200000(代表2023-08-13 17:00:00)。

select from_utc_timestamp(date '2023-08-14 00:00:00','PST');

返回NULL。

select from_utc_timestamp('2023-08-13',null);

相关文档