Hive SQL时间戳函数

一.unix_timestamp函数

1.unix_timestamp函数返回当前时间戳,current_timestamp()也有同样作用

hive> select unix_timestamp();
OK
1574423914
Time taken: 0.435 seconds, Fetched: 1 row(s)

2.unix_timestamp(‘2019-11-22 00:00:00’)返回’2019-11-22 00:00:00’对应的时间戳

hive> select unix_timestamp('2019-11-22 00:00:00');
OK
1574352000
Time taken: 0.071 seconds, Fetched: 1 row(s)

3.unix_timestamp(‘2019/11/22 00/00/00’,‘yyyy/MM/dd HH/mm/SS’)返回’2019/11/22 00/00/00’对应的时间戳,指定时间戳的格式

hive> select unix_timestamp('2019/11/22 00/00/00','yyyy/MM/dd HH/mm/SS');
OK
1574352000
Time taken: 0.084 seconds, Fetched: 1 row(s)
二.from_unixtime函数

from_unixtime(123456789)返回123456789时间戳的日期,格式为yyyy-MM-dd HH:mm:ss

hive> select from_unixtime(123456789);
OK
1973-11-30 05:33:09
Time taken: 0.07 seconds, Fetched: 1 row(s)

from_unixtime(123456789,‘yyyy/MM/dd HH/mm/ss’)返回timestamp时间戳,并指定对应日期格式

hive> select from_unixtime(123456789,'yyyy/MM/dd HH/mm/ss');
OK
1973/11/30 05/33/09
Time taken: 0.035 seconds, Fetched: 1 row(s)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值