[英]I want to fetch the ISO Date which is stored as “string” format in Mongodb and convert it to Date format in nodejs
我想獲取以“字符串”格式存儲在 Mongodb 中的 ISO 日期,並將其轉換為 Nodejs 中的日期格式。 API里面我想試試
app.get('/hrTable', jsonParser, (req, res) => {
MongoClient.connect("mongodb://localhost:27017/CSS_RAG", {
useUnifiedTopology: true }, function (err, db) {
if (err) reject(err);
var dbo = db.db("CSS_RAG");
var query = {};
for (var key in req.query) {
req.query[key] !== "" ? query[key] = req.query[key] : null;
}
dbo.collection("hrTable").find(
query,
{ sort: { Date: -1 } }).toArray(function (err, result) {
if (err) reject(err);
db.close();
resolve(result);
res.send(result);
}
)})})
試試這個
date = new Date(ISODate("1960-07-30T00:00:00.000+0000"));
date.getFullYear()+'-' + (date.getMonth()+1) + '-'+date.getDate();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.