时间
1.时间戳
秒数时间戳--10位
hive只支持10位的时间戳
毫秒时间戳--13位
时间-->时间戳(13位),乘以 1000
13位时间戳-->日期(除以1000)
(1)时间戳(10位)-》日期:from_unixtime select from_unixtime(1441565203,'yyyy/MM/dd HH:mm:ss') from test_date; 输出:2015/09/07 02:46:43 (2)时间戳(13位)-》日期:from_unixtime select from_unixtime(cast(1483675004884/1000 as bigint),"yyyy-MM-dd HH:mm:ss") 输出:2017-01-06 11:56:44 (3)日期-》时间戳(10位):unix_timestamp select unix_timestamp('2015-09-07 02:46:43') from test_date; 输出:1441565203
2.字符串获取时间
(4)字符串-》日期: to_date select to_date('2011-12-08 10:03:01') from test_date; 输出::2011-12-08 (5)字符串-》年/月/日/时/分/秒 select year('2011-12-08 10:03:01') from test_date; 输出:2011
3.时间函数
(6) 日期差值 datediff select datediff('2012-12-08','2012-05-09')from dual 输出:213 (7)日期增加/减少函数: date_add/date_sub select date_sub('2012-12-08',10)from dual 输出:2012-11-28
4.时间格式化
时间格式化:字符串必须是"2019-06-29"模式,而不是"2019/06/09"
select date_format("2019/06/09","yyyy-MM-dd"); NULLselect date_format(regexp_replace("2017/06/09","/","-"),"yyyy-MM-dd"); 2017-06-09
select date_format("2019-06-29","yyyy-MM-dd"); 2019-06-29select date_format("2019-06-29","yyyy"); 2019select date_format("2019-06-29","yyyy/MM/dd"); 2019/06/29
posted on 2019-01-09 17:56 happygril3 阅读(165) 评论(0) 收藏 举报
浙公网安备 33010602011771号