我在格式化具有毫秒的日期和时间时遇到了问题。
说明:csv 中的日期格式分布在前 3 列 2014/12/22,14:48:51,800 中,分别为日期、时间和毫秒。所以,我基本上将它们合并为 1。在这里,为了说明,我取了 1 行数据框
temp
#[1] "2014/12/22" "14:48:51" "800"
temp <- gsub("/","-",paste(temp[1],paste(temp[2],temp[3],sep="."),sep=" "))
#[1] "2014-12-22 14:48:51.800"
然后,设置选项
op <- options(digits.secs = 3)
options(op)
Date_time <- as.POSIXlt(strptime(temp, format="%Y-%m-%d %H:%M:%OS"))
#[1] "2014-12-22 14:48:51.8 IST"
上面的输出会给我 "2014-12-22 15:10:41.8 IST" 。但是,对于 8 毫秒和 80 毫秒,它也会给出相同的输出“2014-12-22 15:10:41.8 IST”
另外,如果我使用 format="%Y-%m-%d %H:%M:%OS3" 我得到 NA。