0
点赞
收藏
分享

微信扫一扫

HIVE 时间类型转换函数 from_unixtime和unix_timestamp

天蓝Sea 2022-04-27 阅读 26
hive
时间类型:
  • 时间戳 timestamp
  • 日期 date
create table testDate(
    ts timestamp
    ,dt date
) row format delimited fields terminated by ',';

// 2022-02-19 14:24:57.200,2022-02-19
  • 时间戳与时间字符串转换
// from_unixtime 传入一个时间戳以及pattern(yyyy-MM-dd) 可以将 时间戳转换成对应格式的字符串
select from_unixtime(1630915221,'yyyy年MM月dd日 HH时mm分ss秒')

// unix_timestamp 传入一个时间字符串以及pattern,可以将字符串按照pattern转换成时间戳
select unix_timestamp('2021年09月06日 16时00分21秒','yyyy年MM月dd日 HH时mm分ss秒');
select unix_timestamp('2021-01-14 14:24:57.200')
select unix_timestamp() //默认返回当前时间戳

select unix_timestamp()+24*60*60 //当前时间+1天
select from_unixtime(unix_timestamp()+24*60*60,'yyyy/MM/dd HH:mm:ss')

举报

相关推荐

0 条评论