简体   繁体   English

Hive - 在 hive sql 中将纪元时间(毫秒 - 13 位)转换为时间戳直到毫秒

[英]Hive - Convert epoch time (ms - 13 digit) to timestamp till milliseconds in hive sql

I need to get completed timestamp from epoch timestamp in hive query.我需要从 hive 查询中的纪元时间戳获取完整的时间戳。

For example 
epoch time      --- 1606407266850
timestamp value --- 2020-11-26 21:44:26 
expected value  --- 2020-11-26 21:44:26.850

My method in hive:我在 hive 中的方法:

Select timestamp(concat(from_unixtime(CAST(lastModifiedOn AS BIGINT),'yyyy-MM-dd HH:mm:ss'),".",CAST(lastModifiedOn AS BIGINT)%1000),'yyyy-MM-dd HH:mm:ss.SSS')
from db.table1

My question: Do we have better approach to get timestamp value till millisecond?我的问题:我们是否有更好的方法来获取直到毫秒的时间戳值? we can easily get value till second.我们可以轻松获得第二名的价值。

select cast(lastModifiedOn/1000 as timestamp);

Can't specify the precision but will keep the timestamp up to the highest precision无法指定精度,但会将时间戳保持在最高精度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM