@lpm.dev/neo.uuid

Pool

uuid

Zero-dependency UUID library - Modern, tree-shakeable alternative to uuid package

install @lpm.dev/neo.uuid

extractTimestamp

function
function extractTimestamp(uuid: string): Date | null

Extract timestamp from UUID v7 as Date Extracts the 48-bit Unix timestamp (in milliseconds) from a UUID v7 and returns it as a JavaScript Date object. UUID v7 stores a millisecond-precision timestamp in the first 48 bits, making it possible to extract the exact time the UUID was generated.

Parameters

uuidstringUUID v7 string

Returns

Date | nullDate object or null if not a valid v7 UUID

Example

const id = uuidv7()
const timestamp = extractTimestamp(id)
// Date object representing when the UUID was generated

const date = new Date('2025-01-15T12:00:00.000Z')
const id2 = uuidv7({ timestamp: date.getTime() })
const extracted = extractTimestamp(id2)
console.log(extracted.toISOString()) // '2025-01-15T12:00:00.000Z'