Skip to content

Instantly share code, notes, and snippets.

@scottcorgan
Created July 5, 2012 17:28
Show Gist options
  • Save scottcorgan/3055049 to your computer and use it in GitHub Desktop.
Save scottcorgan/3055049 to your computer and use it in GitHub Desktop.
Pull date out of MongoDB ObjectID
var id = "4ff5cd62cb40c7010000000f";
var timehex = id.substring(0,8);
console.log(timehex);
var secondsSinceEpoch = parseInt(timehex, 16);
console.log(secondsSinceEpoch);
var dt = new Date(secondsSinceEpoch*1000);
console.log(dt);​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment