How can I format a date coming from MongoDB?

前端 未结 7 640
青春惊慌失措
青春惊慌失措 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:58

    My solution is:

    Add momentjs to your express application locals like this:
    app.locals.moment = require('moment');

    Then you can use moment in any jade files:
    span='(Created at: ' + moment(obj.createTime).format("YYYY/MM/DD") + ')'

    Reference: Making use of utility libraries in server-side Jade templates

提交回复
热议问题