当前位置: 代码迷 >> 综合 >> HIVE中的from_unixtime函数
  详细解决方案

HIVE中的from_unixtime函数

热度:81   发布时间:2023-09-14 15:41:48.0

hive中的from_unixtime()函数,可以把时间戳格式的时间,转化为年月日时分秒格式的时间。

from_unixtime的参数要求为整数,且单位为秒。

如果从业务系统拿到的时间戳格式的时间单位为毫秒,则需要先将它转化为秒,方法如下

from_unixtime( int (timestamp_in_millisecond / 1000))示例:
hive (default)> select from_unixtime(1556803199);
OK
_c0
2019-05-02 21:19:59
Time taken: 0.051 seconds, Fetched: 1 row(s)hive (default)> select from_unixtime(int(1556803199681/1000), "yyyy-MM-dd"); 
OK
_c0
2019-05-02
Time taken: 0.055 seconds, Fetched: 1 row(s)