HIVE SQL中13位毫秒时间戳转化为标准日期

HIVE SQL中13位毫秒时间戳转化为标准日期

from_unixtime(BIGINT unixtime [, STRING format])
from_unixtime函数 使用时间戳单位必须是秒

create_time为BIGINT格式,转化为秒
create_time/1000 但结果变为DOUBLE格式
用cast先转换

from_unixtime(cast(create_time/1000 as bigint)) as begin_time

HIVE中不填写格式默认转化为标准格式。
也可以写成所需格式:

from_unixtime(cast(create_time/1000 as bigint),'yyyy-MM-dd HH:mm:ss') as begin_time

要注意’yyyy-MM-dd HH:mm:ss’的大小写 mm相同无法区分,所以用大小写区分月份和分钟。

你可能感兴趣的:(HIVE)