我是靠谱客的博主 开放云朵,最近开发中收集的这篇文章主要介绍hive:函数:日期函数:UNIX时间戳和日期函数 互转,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

今天
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss')

UNIX时间戳转日期函数: from_unixtime

语法: from_unixtime(bigint unixtime[, string format])

 

返回值: string

说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式

举例:

//10位时间戳

select from_unixtime(1323308943,'yyyyMMdd'); --20111208
select from_unixtime(1323308943,'yyyy-MM-dd');  --2011-12-08

//13位时间戳

select from_unixtime(ceil(1472215944000/1000),'yyyy-MM-dd')

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

语法: unix_timestamp()

 

返回值: bigint

说明: 获得当前时区的UNIX时间戳

举例:

select unix_timestamp() --1563159902

日期转UNIX时间戳函数: unix_timestamp

语法: unix_timestamp(string date)

 

返回值: bigint

说明: 转换格式为“yyyy-MM-dd HH:mm:ss“的日期到UNIX时间戳。如果转化失败,则返回0。

举例:

select unix_timestamp('2011-12-08 13:01:03') --1323320463 需带时分秒

指定格式日期转UNIX时间戳函数: unix_timestamp

语法: unix_timestamp(string date, string pattern)

 

返回值: bigint

说明: 转换pattern格式的日期到UNIX时间戳。如果转化失败,则返回0。

举例:

select unix_timestamp('2011-12-07 13:01:03','yyyy-MM-dd HH:mm:ss')  --1323234063

 

参考:

https://www.cnblogs.com/linn/p/6028385.html 

最后

以上就是开放云朵为你收集整理的hive:函数:日期函数:UNIX时间戳和日期函数 互转的全部内容,希望文章能够帮你解决hive:函数:日期函数:UNIX时间戳和日期函数 互转所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部