12 ejs
我在ejs中显示日期
<%= new Date();%>
Run Code Online (Sandbox Code Playgroud)
它给了我结果
2016年2月2日星期二16:02:24 GMT + 0530(IST)
但我需要表现为
2016年1月19日
我怎样才能在ejs中这样做?
gmu*_*hna 21
你可以用一下
在你的控制器中,
var moment = require('moment');
exports.index = function(req, res) {
res.render('index', { moment: moment });
}
Run Code Online (Sandbox Code Playgroud)
在你的HTML中,
<html>
<h1><%= moment().format('Do MMMM, YYYY'); %></h1>
</html>
Run Code Online (Sandbox Code Playgroud)
帖子很旧,但是万一有人碰到这个问题。
您可以消除安装过程,而只需编写一小段代码。添加.toDateString()将在ejs中为您提供上述格式。
但是,Moment用于更详细的日期,例如日,月或年等。
| 归档时间: |
|
| 查看次数: |
15585 次 |
| 最近记录: |