简体   繁体   English

MongoDB ObjectID和日期提取

[英]MongoDB ObjectID and date extraction

I'm extracting the creation date from the MongoDB ObjectID and output this in Jade template engine. 我从MongoDB ObjectID中提取创建日期,并将其输出到Jade模板引擎中。 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) 这是我的输出: 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 但我想要短些的东西,像这样: Fri Sep 13 2013

Can someone please tell me how to do this. 有人可以告诉我该怎么做。

client._id.getTimestamp() returns a Date Object. client._id.getTimestamp()返回一个Date对象。

So you'll need to format the date. 因此,您需要格式化日期。

Here is how you can do it with dateformat module: 使用dateformat模块的方法如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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