【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 / 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,就是想要的结果

所以处理办法是:

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

相关推荐

  1. python生成13时间

    2023-12-20 23:22:02       19 阅读
  2. Hive常用函数_16时间日期处理

    2023-12-20 23:22:02       21 阅读
  3. [C语言]时间

    2023-12-20 23:22:02       44 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-20 23:22:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-20 23:22:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-20 23:22:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-20 23:22:02       18 阅读

热门阅读

  1. Python中文本颜色修改的方法

    2023-12-20 23:22:02       37 阅读
  2. 王昌龄最经典的8首唐诗

    2023-12-20 23:22:02       41 阅读
  3. 获取用户密码的方法与编程实现

    2023-12-20 23:22:02       38 阅读
  4. I/O模型及相似概念

    2023-12-20 23:22:02       35 阅读
  5. ardupilot开发 --- AP_Proximity_RPLidarA2 注释篇

    2023-12-20 23:22:02       32 阅读
  6. 接收Rx动态容器PDU的嵌入式实现

    2023-12-20 23:22:02       37 阅读
  7. 2023.12.20力扣每日一题

    2023-12-20 23:22:02       49 阅读