应用程序.js
app.get('/user.html', function(req, res){
dbConnect.collection("users").find().toArray(function(err, docsData) {
res.render('user', {
data: docsData,
title: "EJS example",
header: "Some users"
});
});
});
用户.html
<% data.forEach(function(user){ %>
<tr>
<td>
<%= user.date %>
</td>
</tr>
<% }) %>
输出为 2014-12-24T09:47:07.436Z
这是来自 mongodb 的值。我想将其格式化为 2014 年 12 月 24 日。如何在嵌入式js中格式化它。