File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11+++
22title =" Time"
33date =2023-08-15
4- updated = 2026-05-15
4+ updated = 2026-07-17
55extra = { series = " Rust" }
66taxonomies = { tags = [" Rust" ] }
77+++
@@ -303,4 +303,25 @@ today: 2026-05-15
303303Dominica Time: 2026-05-15T14:12:06.779365104-04:00[America/Dominica]
304304```
305305
306+ # Extracting timestamps from UUIDv7
307+
308+ ``` rust
309+ fn main () -> Result <(), jiff :: Error > {
310+ let uuid_v7 = uuid :: Uuid :: now_v7 ();
311+ println! (" Generated UUIDv7: {uuid_v7}" );
312+
313+ if let Some (uuid_ts ) = uuid_v7 . get_timestamp () {
314+ let (seconds , nanos ) = uuid_ts . to_unix ();
315+ let jiff_ts = jiff :: Timestamp :: new (seconds as i64 , nanos as i32 )? ;
316+ let dt : jiff :: Zoned = jiff_ts . to_zoned (jiff :: tz :: TimeZone :: system ());
317+
318+ println! (" {dt}" );
319+ // Output: 2025-01-20T10:14:30.123456789-05:00[America/New_York] (for example)
320+ } else {
321+ println! (" This UUID does not contain a timestamp." );
322+ }
323+ Ok (())
324+ }
325+ ```
326+
306327[ custom ] : https://docs.rs/jiff/latest/jiff/fmt/strtime/trait.Custom.html
You can’t perform that action at this time.
0 commit comments