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?
Since Node. js is based on JavaScript, you can use the Date object methods getDate() , getMonth() , and getFullYear() to get the current day, month, and year in a Node.
Custom Date Formatter Function It could be in yy/dd/mm or yyyy-dd-mm format, or something similar.
To check if a date is today's date:Use the Date() constructor to get today's date. Use the toDateString() method to compare the two dates. If the method returns 2 equal strings, the date is today's date.
Either use ISO 8601 format as Phil suggested, or simply pass the date as milliseconds (since 1970). For example, new Date(1447378736842) is the same as new Date("2015-11-13T01:38:56.842Z") . To get the current date in ISO 8601 format, you might do something like this: var d = new Date(); var n = d.
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:
This is old, but I do the following:
return (new Date()).toLocaleDateString()
Returns a date 'mm/dd/yyyy' format, in no additional libs required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With