蜂巢日期转换为毫秒

Hive date cast chopping of milli seconds

以下日期投射不显示毫秒。

select from_unixtime(unix_timestamp("2017-07-31 23:48:25.957" , "yyyy-MM-dd HH:mm:ss.SSS"));

2017-07-31 23:48:25

毫秒的获取方式是什么?

谢谢。

因为unix_timestamp是基于秒的,所以它截断了毫秒。

相反,您可以使用 date_format 将字符串转换为时间戳,这样可以保留毫秒数。然后 from_utc_timestamp.

select from_utc_timestamp(date_format("2017-07-31 23:48:25.957",'yyyy-MM-dd HH:mm:ss.SSS'),'UTC') as datetime

由于此字符串是 ISO 格式,因此可以直接进行转换

hive> select cast("2017-07-31 23:48:25.957" as timestamp);
OK
2017-07-31 23:48:25.957

hive> select timestamp("2017-07-31 23:48:25.957");
OK
2017-07-31 23:48:25.957