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函数。下面为支持的时间模式的字符串