Datetime formatting / customization in ejs

后端 未结 6 1913
清歌不尽
清歌不尽 2021-02-07 04:09

I show date by this in ejs

<%= new Date();%>

it give me result

Tue Feb 02 2016 16:02:24 GMT+0530 (IST)

6条回答
  •  无人及你
    2021-02-07 04:54

    You can use moment

    In your controller,

    var moment = require('moment');
    exports.index = function(req, res) {
        res.render('index', { moment: moment });
    }
    

    In your html,

    
        

    <%= moment().format('Do MMMM, YYYY'); %>

    EDIT :

    If you can live without ordinal day (th, nd, rd etc) you could use basic JS

    <%= new Intl.DateTimeFormat('en-GB', { year: 'numeric', month: 'long', day: '2-digit'}).format(new Date()) %>
    // Expected output: 25 August 2020
    

提交回复
热议问题