1:现象:项目里安装moment npm install moment –save
2:app.js配置
var moment = require(‘moment’);
var shortDateFormat = “ddd @ h:mmA”;
app.locals.moment = moment;
app.locals.shortDateFormat = shortDateFormat;
这样就可以在ejs里解析时间戳了
<%= moment(new Date(parseInt(“要解析的值”)*1000)).format(‘YYYY-MM-DD’) %>
使用Moment.js处理时间戳
本文介绍了如何在项目中利用Node.js的Moment库来安装并配置时间处理功能,通过简单的示例展示了如何在EJS模板中解析和格式化时间戳。
495

被折叠的 条评论
为什么被折叠?



