Avatar ·

How to get current time in milliseconds in Rust?

Hello colleagues! I've just started learning Rust and encountered a task that seems simple but has me stuck. I need to measure the execution time of a small piece of code or just get the current timestamp in milliseconds (unix time with millisecond precision). In other languages (e.g., JavaScript — `Date.now()`, Python — `time.time() * 1000`) this is done in one line, but in Rust I got confused with types and crates. I wrote this code: ```rust use std::time::SystemTime; fn main() { let now = SystemTime::now(); // How to get u64 or f64 in milliseconds from now? println!("Current time: {:?}", now); } ``` But `println!` outputs something like `SystemTime { tv_sec: 1234567, tv_nsec: 890123456 }`, while I need just a number, e.g., `1712345678890`.