我正在编写一个RScript,以比较当前的系统时间戳和MongoDB上一次更新的时间戳。我的方法:
db.runs.find().sort({'id':-1}).limit(1) -给出了最后更新记录的对象ObjectId("5b27f3957cf77b51d60c1502").getTimeStamp() -输出: ISODate("2018-06-18T18:01:57Z")这些步骤能否在R中编写脚本,以便我可以将此ISODate与当前的系统时间戳进行比较?或者是否有其他方法来达到这一要求?
发布于 2020-03-02 18:50:25
这一职能对我来说是有效的:
library(base)
get_date_from_objectid <- function(oid) {
#Get first 8 Hexa characters from ObjectId corresponding with the datetime:
datetime_Hex <- paste("0x", substr(oid, 0, 8), sep = "")
#Convert from Hexa to Decimal using base::strtoi():
datetime_Decimal <- strtoi(c(datetime_Hex))
#Get the date from de the decimal value:
date = as.Date.POSIXct(datetime_Decimal, origin="1970-01-01")
return(date)
}
#Example
objectId= "5dfce6ad859e645780f88b53"
get_date_from_objectid(objectId)
#This will return "2019-12-20"https://stackoverflow.com/questions/50934298
复制相似问题