Hive 时间戳日期函数总结

说明

基于Hive的数据开发工作中,常常用到时间戳,日期各种格式转换,今天抽时间梳理一下。

1. 获取当前UNIX时间戳函数: unix_timestamp

select unix_timestamp();
1711268556

2、UNIX时间戳转日期函数: from_unixtime

 select from_unixtime(1711268371,'yyyyMMdd');
--20240324
 select from_unixtime(1711268371,'yyyy-MM-dd');
--2024-03-24
 select from_unixtime(1711268371,'yyyy-MM-dd hh:mm:ss');
--2024-03-24 08:19:31
 select from_unixtime(1711268371,'yyyy-MM-dd hh:mm:ss:sss');
--2024-03-24 08:19:31:031

3. 日期转UNIX时间戳函数: unix_timestamp

select unix_timestamp('2024-03-24','yyyy-MM-dd');
--1711238400
select unix_timestamp('2024-03-24 08:19:31','yyyy-MM-dd hh:mm:ss');
--1711268371
select unix_timestamp('2024-03-24 08:19:31:031','yyyy-MM-dd hh:mm:ss:sss');
--1711268371

 

posted @ 2024-03-24 16:29  晓枫的春天  阅读(204)  评论(0编辑  收藏  举报