Node.js 显示mongoDB日期之前日期的把手视图-使用日期fns格式
mongoDB集合中有一个日期字段,我试图在表单上显示为:Node.js 显示mongoDB日期之前日期的把手视图-使用日期fns格式,node.js,mongodb,date-fns,handlebarshelper,Node.js,Mongodb,Date Fns,Handlebarshelper,mongoDB集合中有一个日期字段,我试图在表单上显示为: issueDate: 2020-10-09T00:00:00.000Z hbs.handlebars.registerHelper("formatDate", function(mongoDBDate) { if (!mongoDBDate == "") { var displayDate = format(new Date(mongoDBDate), &
issueDate: 2020-10-09T00:00:00.000Z
hbs.handlebars.registerHelper("formatDate", function(mongoDBDate) {
if (!mongoDBDate == "") {
var displayDate = format(new Date(mongoDBDate), "yyyy-MM-dd", {timeZone: "America/New_York"});
return displayDate
}
else {
return mongoDBDate;
}
})
我的车把视图仅尝试显示格式化日期…如下所示:
</div>
<div class="form-group">
<label>Date Added</label>
<input type="date"
class="form-control"
name="issueDate"
placeholder="MM/dd/yyyy"
value="{{formatDate document.issueDate}}">
<div class="text-danger">
{{document.issueDate}}
</div>
</div>
我的formatDate Handlebar.helper代码是:
issueDate: 2020-10-09T00:00:00.000Z
hbs.handlebars.registerHelper("formatDate", function(mongoDBDate) {
if (!mongoDBDate == "") {
var displayDate = format(new Date(mongoDBDate), "yyyy-MM-dd", {timeZone: "America/New_York"});
return displayDate
}
else {
return mongoDBDate;
}
})
但是,无论mongoDB中的日期是什么,或者传递给助手的日期是什么,助手似乎都会收到前一天的日期。我看不出有什么可以这样做。我怀疑这是一个时区问题(mongoDB将日期存储在GMT中)…但我尝试了很多方法都没有成功
欢迎任何建议