irpas技术客

hive 日期和时间戳互相转化_大数据界的扛把子_hive时间戳转换日期格式

irpas 3725

一 . 日期转时间戳

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

?


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #hive时间戳转换日期格式 # #日期转时间戳1 #unix_timestamp #16364622392