蜂巢日期铸造斩千秒
问题描述:
下面的日期铸造不显示毫秒。蜂巢日期铸造斩千秒
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
获得毫秒的方法是什么?
谢谢。
答
由于这个字串是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
答
因为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
https://*.com/questions/32237365/hive-from -unixtime-with-milliseconds –
为什么不把它当作时间戳而不是字符串呢? –