一.unix_timestamp函数
1.unix_timestamp函数返回当前时间戳,current_timestamp()也有同样作用
hive> select unix_timestamp();
OK
1574423914
Time taken: 0.435 seconds, Fetched: 1 row(s)
2.unix_timestamp(‘2019-11-22 00:00:00’)返回’2019-11-22 00:00:00’对应的时间戳
hive> select unix_timestamp('2019-11-22 00:00:00');
OK
1574352000
Time taken: 0.071 seconds, Fetched: 1 row(s)
3.unix_timestamp(‘2019/11/22 00/00/00’,‘yyyy/MM/dd HH/mm/SS’)返回’2019/11/22 00/00/00’对应的时间戳,指定时间戳的格式
hive> select unix_timestamp('2019/11/22 00/00/00','yyyy/MM/dd HH/mm/SS');
OK
1574352000
Time taken: 0.084 seconds, Fetched: 1 row(s)
二.from_unixtime函数
from_unixtime(123456789)返回123456789时间戳的日期,格式为yyyy-MM-dd HH:mm:ss
hive> select from_unixtime(123456789);
OK
1973-11-30 05:33:09
Time taken: 0.07 seconds, Fetched: 1 row(s)
from_unixtime(123456789,‘yyyy/MM/dd HH/mm/ss’)返回timestamp时间戳,并指定对应日期格式
hive> select from_unixtime(123456789,'yyyy/MM/dd HH/mm/ss');
OK
1973/11/30 05/33/09
Time taken: 0.035 seconds, Fetched: 1 row(s)