Node.js 从mongodb获取数据时如何使用momentjs格式化时间
当我从MongoDB获取数据时,我不知道如何使用时刻来格式化时间 我试过了 这是在我的app.js中设置的模式Node.js 从mongodb获取数据时如何使用momentjs格式化时间,node.js,mongodb,momentjs,ejs,node-modules,Node.js,Mongodb,Momentjs,Ejs,Node Modules,当我从MongoDB获取数据时,我不知道如何使用时刻来格式化时间 我试过了 这是在我的app.js中设置的模式 var blogSchema = new mongoose.Schema({ title: String, author: String, body: String, image: String, created: {type:Date, default:Date.now} }); 在我的Show.ejs页面上 <div class
var blogSchema = new mongoose.Schema({
title: String,
author: String,
body: String,
image: String,
created: {type:Date, default:Date.now}
});
在我的Show.ejs页面上
<div class="ui text main container segment">
<div class="ui huge header"><%=blog.title%></div>
<div class="ui top attached">
<div class="item">
<img class="ui centered rounded image" src="<%=blog.image%>">
<div class="content">
<span><%=blog.created%></span>
</div>
<div class="description">
<p><%=blog.body%></p>
</div>
</div>
</div>
</div>
我希望日期格式是这样的
矩。格式为'MMMM Do YYYY,h:mm:ss a';//2019年2月6日凌晨2:31:46
var moment = require('moment');
app.locals.moment = require('moment'); // this makes moment available as a variable in every EJS page
和on Show.ejs
<%= moment(blog.created).format('MMMM Do YYYY, h:mm:ss a')%>
<%= moment(blog.created).format('MMMM Do YYYY, h:mm:ss a')%>