如何將以毫秒為單位的數字時間轉換為datetime帶有十進制值的秒格式(最好使用lubridate?
time = 1633708877772
uj5u.com熱心網友回復:
隨著lubridate,使用as_datetime
library(lubridate)
as_datetime(time/1000)
[1] "2021-10-08 16:01:17 UTC"
請注意,print控制臺中未顯示毫秒。如果我們需要列印,則用strftimeor格式化format(但它不再是日期時間物件)
strftime(as_datetime(time/1000), '%Y-%m-%d %H:%M:%OS3')
#[1] "2021-10-08 11:01:17.772"
或者不使用任何包,只需在 as.POSIXct
as.POSIXct(time/1000, origin = '1970-01-01')
[1] "2021-10-08 11:01:17 CDT"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/357907.html
