Skip to content

Instantly share code, notes, and snippets.

@wllmsash
Created October 7, 2023 21:22
Show Gist options
  • Save wllmsash/bcb337ce0662ed044012e2d7170f7ed0 to your computer and use it in GitHub Desktop.
Save wllmsash/bcb337ce0662ed044012e2d7170f7ed0 to your computer and use it in GitHub Desktop.
UUIDv7 Get Timestamp
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