Node.js 清理MongoDB中的日期,以便在前端显示
我有一些导入的日期,它们在Mongo中保存为日期,当我将它们取出时,Mongo会附加UTC时间等等 当我从节点中检索日期时,我如何清理它们,使它们看起来很好 电流输出: 2011年1月20日星期四00:00:00 GMT-0700(MST) 如果我能在2011年后删除所有内容,那就好了…通过Date() 可以通过向date()方法传递datetime字符串来指定特定日期。例如:Node.js 清理MongoDB中的日期,以便在前端显示,node.js,mongodb,Node.js,Mongodb,我有一些导入的日期,它们在Mongo中保存为日期,当我将它们取出时,Mongo会附加UTC时间等等 当我从节点中检索日期时,我如何清理它们,使它们看起来很好 电流输出: 2011年1月20日星期四00:00:00 GMT-0700(MST) 如果我能在2011年后删除所有内容,那就好了…通过Date() 可以通过向date()方法传递datetime字符串来指定特定日期。例如: new Date("<YYYY-mm-dd>") which returns the ISODate wi
new Date("<YYYY-mm-dd>") which returns the ISODate with the specified date.
new Date("<YYYY-mm-ddTHH:MM:ss>") which specifies the datetime in local datetime and returns the ISODate with the specified datetime in UTC.
new Date("<YYYY-mm-ddTHH:MM:ssZ>") which specifies the datetime in UTC and returns the ISODate with the specified datetime in UTC.
我们可以这样格式化它
db.collection.aggregate(
[
{
$project: {
yearMonthDay: { $dateToString: { format: "%Y-%m-%d", date: "$date" } },
time: { $dateToString: { format: "%H:%M:%S:%L", date: "$date" } }
}
}
]
)
您可以通过Date()
可以通过向date()方法传递datetime字符串来指定特定日期。例如:
new Date("<YYYY-mm-dd>") which returns the ISODate with the specified date.
new Date("<YYYY-mm-ddTHH:MM:ss>") which specifies the datetime in local datetime and returns the ISODate with the specified datetime in UTC.
new Date("<YYYY-mm-ddTHH:MM:ssZ>") which specifies the datetime in UTC and returns the ISODate with the specified datetime in UTC.
我们可以这样格式化它
db.collection.aggregate(
[
{
$project: {
yearMonthDay: { $dateToString: { format: "%Y-%m-%d", date: "$date" } },
time: { $dateToString: { format: "%H:%M:%S:%L", date: "$date" } }
}
}
]
)
您可以找到更多详细信息和
`
$inputdate是您的ISO日期
`
$inputdate是您的ISO日期我强烈建议您查看