Skip to content

Instantly share code, notes, and snippets.

@glynnbird
Last active October 21, 2025 15:47
Show Gist options
  • Select an option

  • Save glynnbird/be2b4a1c11397d5aa2dec57ea1d8d5dc to your computer and use it in GitHub Desktop.

Select an option

Save glynnbird/be2b4a1c11397d5aa2dec57ea1d8d5dc to your computer and use it in GitHub Desktop.
ts
function extractMilliseconds(ts) {
// remove any '-' from uuidv7 strings
const hexStr = ts.replace(/\-/g, '')
if (hexStr.length !== 32) return 0
return parseInt(hexStr.substr(0, 12), 16)
}
function toHex(ts) {
return ts.toString(16).padStart(12, '0')
}
const id = '019a0760-ea1d-7e78-b174-09b12c94fdd8'
console.log(extractMilliseconds(id))
// 1761060383261
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment