presto timestmp使用

2021-10-18 11:31:54 浏览数 (3)

日期和时间运算符

时区转化

代码语言:javascript复制
SELECT timestamp '2012-10-31 01:00 UTC';
2012-10-31 01:00:00.000 UTC

SELECT timestamp '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles';
2012-10-30 18:00:00.000 America/Los_Angeles

时间戳、时间和日期

代码语言:javascript复制
select
'1633939200000',
substr('1633939200000',1,10) as a,
from_unixtime(cast(substr('1633939200000',1,10) as int)) as b, -- 将13位毫秒级的unix timestamp截取到秒级别
format_datetime(from_unixtime(cast(substr('1633939200000',1,10) as int)),'yyyy-MM-dd')

结果:

1633939200000

1633939200

2021-10-11 16:00:00.000

2021-10-11

比较举例

代码语言:javascript复制
select  current_timestamp >TIMESTAMP '2021-10-11 16:00'

结果 :

True

官方链接

0 人点赞