如何在dttm对象中打印毫秒

时间:2018-09-25 05:58:44

标签: r datetime printf tibble

ex <- structure(list(rowid = 1:12, timestamp = structure(c(1505577931.8, 
1505577931.8, 1505577931.8, 1509206767.39, 1509206767.39, 1511019574.47, 
1511019574.47, 1511988378.544, 1511988378.544, 1511986281.239, 
1511986281.239, 1512909143.7), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("rowid", 
"timestamp"))

使用上面的数据,如何在timestamp列中显示毫秒?

1 个答案:

答案 0 :(得分:1)

我们可以使用format打印毫秒

format(ex$timestamp, "%Y-%m-%d %H:%M:%OS3")
#[1] "2017-09-16 16:05:31.799" "2017-09-16 16:05:31.799" "2017-09-16 16:05:31.799"
#[4] "2017-10-28 16:06:07.390" "2017-10-28 16:06:07.390" "2017-11-18 15:39:34.470"
#[7] "2017-11-18 15:39:34.470" "2017-11-29 20:46:18.543" "2017-11-29 20:46:18.543"
#[10] "2017-11-29 20:11:21.239" "2017-11-29 20:11:21.239" "2017-12-10 12:32:23.700"