从mongodb id获取时间戳 [英] Getting timestamp from mongodb id

查看:1552
本文介绍了从mongodb id获取时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从MongoDB id获取时间戳?

How do I get the timestamp from the MongoDB id?

推荐答案

时间戳包含在a的前4个字节中mongoDB id(参见: http://www.mongodb.org/display/DOCS/Object+ ID )。

The timestamp is contained in the first 4 bytes of a mongoDB id (see: http://www.mongodb.org/display/DOCS/Object+IDs).

所以你的时间戳是:

timestamp = _id.toString().substring(0,8)

date = new Date( parseInt( timestamp, 16 ) * 1000 )

这篇关于从mongodb id获取时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆