Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 清理MongoDB中的日期,以便在前端显示_Node.js_Mongodb - Fatal编程技术网

Node.js 清理MongoDB中的日期,以便在前端显示

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

我有一些导入的日期,它们在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 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日期

我强烈建议您查看