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

时间戳与日期转换:从Unix到yyyy-MM-dd
本文介绍了如何在SQL中进行时间戳与日期格式的转换,包括使用`from_unixtime`和`unix_timestamp`函数,以及实例展示了如何将时间戳转换为特定格式的字符串和反之。
时间类型:
  • 时间戳 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')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值