栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

hive 日期和时间戳互相转化

hive 日期和时间戳互相转化

一 . 日期转时间戳

1 unix_timestamp()   获取当前时间戳

 select unix_timestamp(); --1636462239

 2 unix_timestamp()  输入日期参数  输入的时间格式必须符合 yyyy-MM-dd HH:mm:ss

select unix_timestamp('2021-11-11 11:11:11'); --1636600271

 3  unix_timestamp()  输入日期参数,并指定日期格式  时间格式指定错 返回null

select unix_timestamp('2021-08-15','yyyy-MM-dd');  --1628956800  --15号零点时间戳

select unix_timestamp('2021-08-15 15','yyyy-MM-dd HH'); 

 二. 时间戳转日期

1 from_unixtime()  将时间戳转化为指定的时间格式

select from_unixtime(1628956800,'yyyy-MM-dd'); --2021-08-15

select from_unixtime(1628956800,'yyyy-MM-dd HH-mm'); 2021-08-15 00-00

2 同理获取当前时间

select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); 2021-11-09 21:13:56

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/460663.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号