2017-08-04 71 views
0

下面的日期鑄造不顯示毫秒。蜂巢日期鑄造斬千秒

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 

獲得毫秒的方法是什麼?

謝謝。

+0

https://stackoverflow.com/questions/32237365/hive-from -unixtime-with-milliseconds –

+0

爲什麼不把它當作時間戳而不是字符串呢? –

回答

1

由於這個字串是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 
-1

因爲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 
+0

是date_fromat蜂巢中有效的內置函數嗎? – TKHN

+0

@TKHN是的,你可以從這裏找到功能描述 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF – Wonjin

+0

其給我錯誤無效函數date_format ..我使用Hive 1.1.0 – TKHN