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

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

1)需求

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

2)实现

sql 复制代码
select from_utc_timestamp(1682238448915, 'GMT+8');
-- 结果:2023-04-23 16:27:28.915000000,包含毫秒了

select from_unixtime(cast(1682238448915 / 1000 as bigint), 'yyyy-MM-dd HH:mm:ss');
-- 结果:2023-04-23 08:27:28,差了8小时

select from_unixtime(cast(substring(1682238448915, 1, 10) as bigint), '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,就是想要的结果

所以处理办法是:

sql 复制代码
select date_format(from_utc_timestamp(1682238448915, 'GMT+8'), 'yyyy-MM-dd HH:mm:ss');
相关推荐
山峰哥2 小时前
数据库工程中的SQL调优策略与实践:从索引优化到执行计划分析
数据库·sql·性能优化
V1ncent Chen2 小时前
从零学SQL 05 基础查询
数据库·sql·mysql·数据分析
夫唯不争,故无尤也4 小时前
Agent 开发者如何快速上手 SQL:从表设计到 Python 交互的一篇实战入门
python·sql·交互
夫唯不争,故无尤也4 小时前
原始文档元数据metadata
java·前端·javascript·sql
啥都想学点4 小时前
pikachu靶场——SQL-Inject—1(Kali系统)
sql·网络安全
Z1eaf_complete5 小时前
SQL注入如何写入Webshell
数据库·sql
王的宝库5 小时前
MapReduce / Hive / Pig :从底层批处理到 SQL/脚本落地
hive·hadoop·sql·mapreduce
V1ncent Chen6 小时前
从零学SQL 02 MySQL架构介绍
数据库·sql·mysql·架构·数据分析
大母猴啃编程6 小时前
MySQL内置函数
数据库·sql·mysql·adb
升职佳兴6 小时前
告别 nohup:Hive Metastore 交给 systemd 托管的完整步骤
数据仓库·hive·hadoop