Created
October 7, 2023 21:22
-
-
Save wllmsash/bcb337ce0662ed044012e2d7170f7ed0 to your computer and use it in GitHub Desktop.
UUIDv7 Get Timestamp
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
import { uuidv7, UUID } from "uuidv7"; | |
const uuid = uuidv7(); | |
const timestampBytes = new Uint8Array(8); | |
timestampBytes.set(new Uint8Array(UUID.parse(uuid).bytes.buffer.slice(0, 6)), 2); | |
const timestampMs = new DataView(timestampBytes.buffer).getBigUint64(); | |
console.log(new Date(Number(timestampMs))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment