Advertisement

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

阅读量:

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

  • 1)需求
  • 2)实现

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');

全部评论 (0)

还没有任何评论哟~