如何解决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;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。