How can I format a date coming from MongoDB?

前端 未结 7 653
青春惊慌失措
青春惊慌失措 2021-01-30 05:19

I\'m using Jade to render my views from within Express.js. I am saving documents in MongoDB and using Mongoose to access my documents. I am saving a default date created when a

7条回答
  •  长发绾君心
    2021-01-30 05:44

    very easy method steps-

    1. install via npm moment --save

    2. declare var moment = require('moment');

    3. define the declare variable in res.render'filename.ejs',{moment: moment});

    4. put this ejs in your view file <%= moment(data.column_name_of_your_date).format( 'DD MMM YYYY'); %>

    output is -- 09 Jun 2017

    you can changed the format check it out in moment link for different format http://momentjs.com/

提交回复
热议问题