0


【Hive-Sql】Hive 处理 13 位时间戳得到年月日时分秒(北京时间)

【Hive-Sql】Hive 处理 13 位时间戳得到年月日时分秒(北京时间)

1)需求

使用 Hive 自带函数 将 13位 时间戳转成年月日时分秒(北京时间),格式样例:

‘2023-01-13 12:23:41’

2)实现

select from_utc_timestamp(1682238448915,'GMT+8');-- 结果:2023-04-23 16:27:28.915000000,包含毫秒了select from_unixtime(cast(1682238448915/1000asbigint),'yyyy-MM-dd HH:mm:ss');-- 结果:2023-04-23 08:27:28,差了8小时select from_unixtime(cast(substring(1682238448915,1,10)asbigint),'yyyy-MM-dd HH:mm:ss');-- 结果:2023-04-23 08:27:28,差了8小时select date_format(from_utc_timestamp(1682238448915,'GMT+8'),'yyyy-MM-dd HH:mm:ss');// 结果:2023-04-23 16:27:28,就是想要的结果

所以处理办法是:

select date_format(from_utc_timestamp(1682238448915,'GMT+8'),'yyyy-MM-dd HH:mm:ss');
标签: hive sql hadoop

本文转载自: https://blog.csdn.net/weixin_53543905/article/details/135079219
版权归原作者 bmyyyyyy 所有, 如有侵权,请联系我们删除。

“【Hive-Sql】Hive 处理 13 位时间戳得到年月日时分秒(北京时间)”的评论:

还没有评论