【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·oracle
禹凕2 小时前
MYSQL——基础知识(SQL的临时表和克隆表)
sql·mysql
空空潍3 小时前
MySQL索引不生效?一文理解CBO成本模型
数据库·sql·mysql
IRevers4 小时前
【Agent】基于Langchain的Agent数据库查询助手
数据库·人工智能·pytorch·sql·深度学习·langchain·agent
他是龙5514 小时前
DVWA SQL 注入全级别通关笔记(Low / Medium / High / Impossible)
数据库·笔记·sql
treacle田4 小时前
达梦数据库-快速装载工具dmfldr-记录总结
数据库·sql·达梦快速装载dmfldr
juniperhan21 小时前
Flink 系列第17篇:Flink Table&SQL 核心概念、原理与实战详解
大数据·数据仓库·分布式·sql·flink
Irene199121 小时前
SQL 中的大小写规则总结:关键字、函数名不区分大小写(建议大写),字符串值、日期格式符严格区分大小写
sql·大小写规范
不剪发的Tony老师21 小时前
DBcooper:一款面向开发者的现代数据库客户端
数据库·sql
你觉得脆皮鸡好吃吗1 天前
SQL注入 基础防御
数据库·sql