hive中日期與時間戳轉換
總結:時間戳到日期時間,日期時間到時間戳,日期時間到日期。
獲取時間戳:select distinct unix_timestamp() from test_date;
時間戳>>>>日期:select distinct from_unixtime(1441565203,'yyyy/MM/dd HH:mm:ss') from test_date;
2015/09/07 02:46:43
日期時間>>>>>>時間戳:預設格式為“yyyy-MM-dd HH:mm:ss“:
select distinct unix_timestamp('2015-09-07 02:46:43') from test_date;
1441565203
指定日期時間>>>>>>時間戳:
select distinct unix_timestamp('20111207 13:01:03','yyyyMMdd HH:mm:ss') from test_date;
1323234063
//要接受的型別
日期時間>>>>>>日期:
select distinct to_date('2011-12-08 10:03:01') from test_date;
結果:2011-12-08
日期時間>>>>>>年/月/日/時/分/秒: year(string date),month(),day(),hour(),minute(),second()。
select distinct year('2011-12-08 10:03:01') from test_date;
2011
select distinct second('2011-12-08 10:03:01') from test_date;
1