Kay*_*Kay 54
我相信ObjectId有一个getTimestamp()方法; 例如
_id.getTimestamp()
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以在使用_id获取创建时间戳的mongoose模式上创建虚拟的 "已创建"属性.只需添加:
YourMongooseSchema.virtual('created').get( function () {
if (this["_created"]) return this["_created"];
return this["_created"] = this._id.getTimestamp();
});
Run Code Online (Sandbox Code Playgroud)
如果你运行这个你会得到时间戳
console.log(new mongoose.Types.ObjectId().getTimestamp() );
Run Code Online (Sandbox Code Playgroud)
例如。
Fri Nov 16 2012 17:20:14 GMT+0000 (GMT)
Run Code Online (Sandbox Code Playgroud)
var timestamp = document._id.toString().substring(0,8);
var date = new Date( parseInt( timestamp, 16 ) * 1000 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13846 次 |
| 最近记录: |