hive时间戳转化格式化

1.bigint转化成时间戳
 1.1 bigint为13位(毫秒级)
  1.date_format函数
  select
     date_format(cast(1577379134405 as timestamp),'yyyyMMddHHmmss')
  2.from_unixtime函数   
  select
    from_unixtime(cast(substr(1577379134405,0,10) as bigint),'yyyyMMddHHmmss')
 
   select
    from_unixtime(cast(1577379134405/1000 as bigint),'yyyyMMddHHmmss')
 
 1.2 bigint为10位(秒级)
   select
     from_unixtime(1577429940,'yyyyMMddHHmmss') 
        
2.时间戳转化为bigint
 2.1 为timestamp时间戳
   select
     unix_timestamp('2019-12-27 14:59:00','yyyy-MM-dd HH:mm:ss')

   select
     unix_timestamp('201912271459','yyyyMMddHHmm')
 2.2 为中文时间戳
    select
      unix_timestamp('Tue May 20 22:41:01 CST 2014','EEE MMM dd HH:mm:Ss z yyyy') 
     select
        unix_timestamp('16/Mar/2017:12:25:01 +0800', 'dd/MMM/yyyy:HH:mm:ss Z')
    select 
        unix_timestamp('2016-08-16T10:02:41Z', "yyyy-MM-dd'T'HH:mm:ss'Z'")
        
注意:1.from_unixtime函数后面的格式分钟一定要mmss,不然结果有问题。2.hive的时间精确到秒级,使用hive时间函数bigint都是10位
3.中文时间戳需要将计算机用户所使用的语言设置为en_US.UTF-8(export LC_ALL=en_US.UTF-8)

2.3由于hive时间格式化调用的是java.text.SimpleDateFormat函数。下面为支持的时间模式的字符串在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值