How to extract a timestamp from UUID v7
The first 48 bits of UUID v7 store Unix time in milliseconds. In the usual hyphenated representation, that is the first two groups: eight hexadecimal digits followed by four. The remaining fields identify the version and variant and provide randomness or ordering data.
For example, 017f22e2-79b0-7cc3-98c4-dc0c0c07398f contains 017f22e279b0, which is 1645557742000 milliseconds, or 2022-02-22T19:22:22.000Z.
Generating IDs in an application? Follow the C# UUID v7 guide or PostgreSQL UUID v7 guide, then return here to verify their timestamps.
JavaScript example
import { validate, version } from "uuid";
function uuidV7ToTimestamp(id) {
if (!validate(id) || version(id) !== 7) {
throw new Error("Expected a valid UUID v7");
}
return Number.parseInt(id.replaceAll("-", "").slice(0, 12), 16);
}
const ms = uuidV7ToTimestamp("017f22e2-79b0-7cc3-98c4-dc0c0c07398f");
console.log(new Date(ms).toISOString());Milliseconds, seconds, and time zones
JavaScript dates use milliseconds. Divide by 1000 and round down for whole Unix seconds. UTC and ISO output describe the same instant; local time uses your browser’s time zone. The embedded value reflects the generator’s timestamp, not proof of when a database row was inserted.
This method is specific to UUID v7. UUID v4 does not contain a timestamp, and UUID v1 uses a different layout and epoch. See RFC 9562, section 5.7 for the specification.
Inspect the UUID’s fields in the decoder, convert a timestamp to UUID v7, or generate UUID v7 IDs.