我尝试将MongoDB日期转换为R日期对象。我用
library(RMongo)
library(data.table)
mongo<-mongoDbConnect("test", host = "127.0.0.1", port = "27017")
event<-dbGetQuery(mongo, "event", "", 0, 1000)
data<-as.data.table(event)
date&lt; -data $ date返回vector:
[1] "Fri Oct 28 13:15:00 CEST 2016" "Fri Oct 28 16:00:00 CEST 2016" "Fri Nov 04 18:30:00 CET 2016" "Fri Nov 04 18:45:00 CET 2016"
我无法转换此向量。我尝试了以下代码:
as.Date(date, format = "%a %b %d %H:%M:%S %Y")
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
strptime(date, format = "%a %b %d %H:%M:%S %Y")
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
我还尝试使用
修改格式s.POSIXct(date, "%a %b %d %H:%M:%S %Z %Y")
Error in as.POSIXct.default(date, "%a %b %d %H:%M:%S %Z %Y")
有人可以解释我是如何做到这一点的,并解释我做错了什么......
非常感谢提前
答案 0 :(得分:0)
我遇到了同样的问题,我发现了两种可能的解决方案:
var updateCartItem = {
Products: [{
"product_idField": "96031",
"skuField": "321005Y-00100-ITM",
"nameField": "Cooper Sunglasses",
"priceField": "75.0000",
"qtyField": 3,
"qtyFieldSpecified": true,
"$$hashKey": "object:8"
},
{
"product_idField": "another",
"skuField": "another-ITM",
"nameField": "Pony Sunglasses",
"priceField": "75.0000",
"qtyField": 1,
"qtyFieldSpecified": true,
"$$hashKey": "object:8"
},
{
"product_idField": "empty",
"skuField": "empty-ITM",
"nameField": "Nobody wants it Sunglasses",
"priceField": "75.0000",
"qtyField": 1,
"qtyFieldSpecified": true,
"$$hashKey": "object:8"
}
]
};
var total = updateCartItem.Products.reduce((a, b) => a + b.qtyField, 0);
console.log(total);
来恢复毫秒。format(yourTime, "%Y-%m-%d %H:%M:%OS3")
,然后再次格式化它们,就像在前一种情况下一样。我希望它有所帮助。
告别