diff --git a/UUID.md b/UUID.md index 1007e99..29b3549 100644 --- a/UUID.md +++ b/UUID.md @@ -10,6 +10,7 @@ https://unpkg.com/uuidv7@1.0.2/dist/index.js https://priver.dev/blog/postgres/implementing-v7-uuid-in-postgres/#:~:text=We%20use%20clock_timestamp%20to%20obtain%20the%20current%20time%2C,millisecond%20timestamp%20to%20a%20byte%20sequence%20using%20int8send. +``` sql CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; create or replace function uuid_generate_v7() @@ -30,7 +31,7 @@ select encode( $$ language SQL volatile; - +``` 3.Extract Timestamp from UUID v7 using Javascript @@ -39,6 +40,8 @@ https://park.is/blog_posts/20240803_extracting_timestamp_from_uuid_v7/ // extract Unix timestamp from a UUID v7 value without an external library 在没有外部库的情况下从 UUID v7 值中提取 Unix 时间戳 + +``` javascript function extractTimestampFromUUIDv7(uuid: string): Date { // split the UUID into its components const parts = uuid.split("-"); @@ -62,4 +65,6 @@ const timestamp = extractTimestampFromUUIDv7(uuid); // check output console.log(timestamp); -// prints "Sat Aug 03 2024 07:09:56 GMT-0500 (Central Daylight Time)" \ No newline at end of file +// prints "Sat Aug 03 2024 07:09:56 GMT-0500 (Central Daylight Time)" + +``` \ No newline at end of file