Datetime formatting / customization in ejs

 ̄綄美尐妖づ 提交于 2019-12-03 11:14:10

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>

You don't need moment js, you can simply use this

<%= new Date().getFullYear();%>

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...

Kiran Raj R

You can do this:

<%= moment(user.date).format( 'MMM-DD-YYYY') %>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!