如何在HiveSQL中将unix纪元时间转换为时间戳?
内置日期函数from_unixtime
将其转换为字符串而不是时间戳。 to_utc_timestamp
似乎只将时间戳从时区转换为 UTC。
是否有任何函数可以直接从 unix 时间戳作为 BIGINT 转换为 TIMESTAMP?
例
SELECT to_timestamp(1427976376) FROM mytable; --> 2015-04-02 14:06:16
编辑:
我能找到的最好的选择,虽然不是很好,是
SELECT cast(from_unixtime(1427976376) as TIMESTAMP) FROM mytable;
尝试以下操作:
SELECT from_unixtime(unix_timestamp) as new_timestamp from mytable...
它将unix时间戳转换为YYYY-MM-DD HH:MM:SS
格式,然后您可以使用以下函数来获取年,月和日:
SELECT year(new_timestamp) as year, month(new_timestamp) as month, day(new_timestamp) as day ...