在Hive中以毫秒为单位的历元到以毫秒为单位的时间戳转换 [英] epoch with milliseconds to timestamp with milliseconds conversion in Hive
本文介绍了在Hive中以毫秒为单位的历元到以毫秒为单位的时间戳转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Hive中将毫秒级的unix历元转换为毫秒级的时间戳?cast()和from_unixtime()函数都无法以毫秒为单位获取时间戳.
How can I convert unix epoch with milliseconds to timestamp with milliseconds In Hive? Neither cast() nor from_unixtime() function is working to get the timestamp with milliseconds.
我尝试过 .SSS
,但是该功能只会增加年份,而不会将其作为毫秒的一部分.
I tried .SSS
but the function just increases the year and doesn't take it as a part of millisecond.
scala> spark.sql("select from_unixtime(1598632101000, 'yyyy-MM-dd hh:mm:ss.SSS')").show(false)
+-----------------------------------------------------+
|from_unixtime(1598632101000, yyyy-MM-dd hh:mm:ss.SSS)|
+-----------------------------------------------------+
|52628-08-20 02:00:00.000 |
+-----------------------------------------------------+
推荐答案
我认为您可以 cast()
:
select cast(1598632101000 / 1000.0 as timestamp)
请注意,这会产生 timestamp
数据类型而不是字符串,如 from_unixtime()
中一样.
Note that this produces a timestamp
datatype rather than a string, as in from_unixtime()
.
这篇关于在Hive中以毫秒为单位的历元到以毫秒为单位的时间戳转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文