May I know how to use moment as a time formatting tool in Koa1?

  node.js, question
  1. Time formatting is an inevitable problem in the project process, and moment is the most widely used package. I found some problems when I tried moment today.
    I quotedmomentAndkoa-locals

app.js

, moment = require('moment')
 , locals = require('koa-locals')(app, locals);
 
 // routers
 var index = require('./routes/index');
 var users = require('./routes/users');
 
 // global middlewares
 app.use(views('views', {
 Root: __dirname plus' /views',
 default: 'ejs'
 }));
 app.use(bodyParser());
 app.use(json());
 app.use(logger());
 app.use(hotreload);
 
 locals.moment = moment;

ejs

< td align="center "> < percentage = moment (user.createtime). format ('yyy-mm-DD') percentage > < /td >
 < td align="center "> < percentage = moment (user.lastlogin). format ('yyy-mm-DD') percentage > < /td >

But the page directly reported the error.

clipboard.png

In the control layer, moment is introduced and then passed into the page template ejs for use.

//Control layer code (koa-controller is used here)
 const moment = require('moment');
 
 xxxxxx
 
 yield this.render('/abc/demo', {moment: moment});
//ejs code
 < td > < percentage = moment (user.createtime). format ('yyyy-mm-ddhh: mm: ss') percentage > < /td >