Created
May 19, 2013 15:40
-
-
Save kumarharsh/5608030 to your computer and use it in GitHub Desktop.
A snippet to convert Mongo ObjectID to javascript timestamps, and vice-versa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----- mongo to js ------ | |
timeStamp = parseInt(Mongo.ObjectId().toString().substr(0,8), 16)*1000 | |
date = new Date(timestamp) | |
----------------------------- | |
----- js to mongo ----- | |
timestamp = new Date().getTime()/1000 | |
mongoId = new ObjectID(timestamp.toString(16)+1e16) |
thanks :)
Thanks . Really handy
Thank you, man :)
Thanks man.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks! that was useful