Last active
October 21, 2025 15:47
-
-
Save glynnbird/be2b4a1c11397d5aa2dec57ea1d8d5dc to your computer and use it in GitHub Desktop.
ts
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 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