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

慈云数据 8个月前 (03-12) 技术支持 125 0

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

  • 1)需求
  • 2)实现

    1)需求

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

    【Hive-Sql】Hive 处理 13 位时间戳得到年月日时分秒(北京时间)
    (图片来源网络,侵删)

    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');
    
    【Hive-Sql】Hive 处理 13 位时间戳得到年月日时分秒(北京时间)
    (图片来源网络,侵删)
微信扫一扫加客服

微信扫一扫加客服

点击启动AI问答
Draggable Icon