Express uses moment for time formatting

         Directly obtain the time and date type in the MySQL database, as shown in the figure on the left, and the type to be converted is shown in the figure on the right

 

The following actions are required:

Look at the following code (the moment.js library is rendered in the ejs file, and the timestamp date is formatted):

1. Install moment in the project: npm install moment --save

2. Write the following code in app.js:

var moment = require('moment');

Write app.locals.moment = moment after var app = express();

 3. The page rendering call format is: <%= moment().format('YYYY-MM-DD')%> 

 

Guess you like

Origin blog.csdn.net/m0_73460278/article/details/126633070