Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

How do I display todays date in Node.js Jade?

I am new to Node.js and Jade and I have tried to use #{Date.now()} and it's giving me numbers. How do I display the date in mm/dd/yy format?

question from:https://stackoverflow.com/questions/12419396/how-do-i-display-todays-date-in-node-js-jade

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use moment.js

First, add moment to your express application locals

express = require('express');
...
app = express();
app.locals.moment = require('moment');

Then you can use moment within a jade template like this:

p #{moment(Date.now()).format('MM/DD/YYYY')}

Moment takes Date.now() by default, so yo can also write:

p #{moment().format('MM/DD/YYYY')}

Sources:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...