Hive中以毫秒为单位的纪元到以毫秒为单位的时间戳转换

问题描述

如何在Hive中将毫秒级的unix历元转换为毫秒级的时间戳? cast()和from_unixtime()函数都无法获得毫秒级的时间戳。

我尝试过.SSS,但是该功能只会增加年份,而不会以毫秒为单位。

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                             |
+-----------------------------------------------------+

解决方法

我认为您可以 $(".chat-history").height($(window).height() - $(".chat-message").height() - $(".header").height()-40); $( window ).resize(function() { $(".chat-history").height($(window).height() - $(".chat-message").height() - $(".header").height()-40); });

cast()

请注意,这会产生select cast(1598632101000 / 1000.0 as timestamp) 数据类型,而不是像timestamp那样的字符串。

,

# Uncomment the next line to define a global platform for your project # platform :ios,'9.0' target 'ApplicationA' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for ApplicationA pod 'Alamofire','~> 5.2' end 使用秒,而不是毫秒。从_unixtime(ts div 1000)以秒为单位转换为时间戳,并以'。'+毫秒(mod(ts,1000))串联,并转换为时间戳。在Hive中测试:

from_unixtime

结果:

with your_data as (
select stack(2,1598632101123,1598632101000) as ts
)

select cast(concat(from_unixtime(ts div 1000),'.',mod(ts,1000)) as timestamp)
from your_data;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...