问题
I show date by this in ejs
<%= new Date();%>
it give me result
Tue Feb 02 2016 16:02:24 GMT+0530 (IST)
But I need to show as
19th January, 2016
How can I do this in ejs?
回答1:
You can use moment
In your controller,
var moment = require('moment');
exports.index = function(req, res) {
res.render('index', { moment: moment });
}
In your html,
<html>
<h1><%= moment().format('Do MMMM, YYYY'); %></h1>
</html>
回答2:
You don't need moment js, you can simply use this
<%= new Date().getFullYear();%>
回答3:
Post is old but in case anyone runs into the issue.
You can eliminate installing moment and write one little line of code. adding .toDateString() will provide you with the above format in ejs.
however, Moment is used for more detailed date, such as Day, or month or year etc...
回答4:
You can do this:
<%= moment(user.date).format( 'MMM-DD-YYYY') %>
来源:https://stackoverflow.com/questions/35151187/datetime-formatting-customization-in-ejs