我的 MongoDB 集合中有一个 ISODate 字段,我想将结果格式化为 dd/mm/yyyy。
我的模型:
const Pedido = new Schema({
id: {
type: String,
required: true
},
cliente: {
type: Schema.Types.ObjectId,
ref: 'clientes',
required: true
},
date: {
type:Date
}
})
mongoose.model('pedidos',Pedido)
那就是查询和渲染的过程:
var query = await Pedido.find().populate('cliente').lean().exec()
res.render("admin/pedidos",{pedidos: query})
我正在使用 handlebars
{{#each pedidos}}
<h5 class="ordem1">Pedido #{{id}} <small>{{date}}</small></h5>
{{/each}}
现在的结果如下:
Wed Apr 08 2020 21:00:00 GMT-0300 (GMT-03:00)
但我希望显示为:08/04/2020
有人能帮我解决这个问题吗?谢谢!