Last active
August 31, 2017 22:06
-
-
Save danielmcq/5246fa52ff7612615dc4f3c32bb4db82 to your computer and use it in GitHub Desktop.
Convert mongo document ID to date
This file contains hidden or 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
function mongoIdToCreatedAt (mongoId) { | |
const datePart = mongoId.slice(0,8) | |
const dateVal = parseInt(datePart,16) | |
return new Date(dateVal*1000) | |
} | |
// One line | |
const mongoIdToCreatedAt = mongoId=>(new Date(parseInt(mongoId.slice(0,8),16)*1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment