Skip to content

Instantly share code, notes, and snippets.

@pablomatiasgomez
Created July 24, 2015 14:22
Show Gist options
  • Save pablomatiasgomez/91d2e3813bb1c308e9c6 to your computer and use it in GitHub Desktop.
Save pablomatiasgomez/91d2e3813bb1c308e9c6 to your computer and use it in GitHub Desktop.
Get the creation date for a generated mongo id
#!/usr/bin/env node
var getDate = function(id) {
return new Date(parseInt(id.toString().slice(0, 8), 16) * 1000);
}
if (process.argv.length > 2) {
process.argv.slice(2).forEach(function (val, i) {
console.log(val + ": " + getDate(val));
});
} else {
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log(getDate(line));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment