【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');
相关推荐
码·蚁1 天前
SpringMVC
数据仓库·hive·hadoop
还是奇怪1 天前
隐藏在字符编码中的陷阱:深入剖析宽字节注入
数据库·sql·安全·web安全
麦聪聊数据1 天前
大数据与云原生数据库中的 SQL2API:优化跨平台数据访问与查询
数据库·sql·云原生
IT 小阿姨(数据库)2 天前
PostgreSQL 之上的开源时序数据库 TimescaleDB 详解
运维·数据库·sql·postgresql·开源·centos·时序数据库
sadandbad2 天前
[vulhub靶机通关]DC-2(rbash绕过_git提权)
网络·sql·web安全·网络安全
杂家2 天前
Hadoop完全分布式部署(超详细)
大数据·hadoop·分布式
BD_Marathon2 天前
【Hadoop】hadoop3.3.1完全分布式配置
大数据·hadoop·分布式
万事大吉CC2 天前
SQL表设计与约束教程
数据库·sql
ANGLAL2 天前
17.MyBatis动态SQL语法整理
java·sql·mybatis
llxxyy卢2 天前
基于时间的 SQL 盲注-延时判断和基于布尔的 SQL 盲注
数据库·sql·oracle