简体   繁体   中英

MongoDB ObjectID and date extraction

I'm extracting the creation date from the MongoDB ObjectID and output this in Jade template engine. Everything works well, but I would like to "limit" the output a bit...

This is the output in my views: Fri Sep 13 2013 09:40:40 GMT+0200 (Västeuropa, sommartid)

But I would like something shorter, like this instead: Fri Sep 13 2013

Can someone please tell me how to do this.

client._id.getTimestamp() returns a Date Object.

So you'll need to format the date.

Here is how you can do it with dateformat module:

var dateformat = require('dateformat'); // npm install dateformat
// ...
var date = client._id.getTimestamp(),
    dateString = dateFormat(date, "ddd mmm dd yyyy"); // pass it to your jade template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM