EJS中的日期时间格式/自定义 [英] Datetime formatting / customization in ejs

查看:537
本文介绍了EJS中的日期时间格式/自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以此在ejs中显示日期

I show date by this in ejs

<%= new Date();%>

给我结果


2016年2月2日星期二16:02 GMT + 0530(IST)

Tue Feb 02 2016 16:02:24 GMT+0530 (IST)

但我需要显示为


2016年1月19日

19th January, 2016

如何

推荐答案

您可以使用时刻

在您的控制器中,

var moment = require('moment');
exports.index = function(req, res) {
    res.render('index', { moment: moment });
}

在您的html中,

<html>
    <h1><%= moment().format('Do MMMM, YYYY'); %></h1>
</html>


编辑:


如果您可以无序地生活(th,nd, rd等),则可以使用基本的 JS

<%= new Intl.DateTimeFormat('en-GB', { year: 'numeric', month: 'long', day: '2-digit'}).format(new Date()) %>
// Expected output: 25 August 2020

这篇关于EJS中的日期时间格式/自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆