下面的日期鑄造不顯示毫秒。蜂巢日期鑄造斬千秒
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
獲得毫秒的方法是什麼?
謝謝。
下面的日期鑄造不顯示毫秒。蜂巢日期鑄造斬千秒
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://stackoverflow.com/questions/32237365/hive-from -unixtime-with-milliseconds –
爲什麼不把它當作時間戳而不是字符串呢? –