SystemTime measures the system clock. Use it when communicating with external entities such as the file system or other processes, or when you need time relative to the Unix epoch. section 17.2
Keep these differences in mind:
- SystemTime is not monotonic: a later real-world operation can have an earlier recorded time if the system clock changes. section 17.2
- Instant measures elapsed time for program operations, while SystemTime corresponds to calendar-like system time. section 17.2
- Compare SystemTime with UNIX_EPOCH through duration_since to obtain elapsed seconds and smaller time units since January 1, 1970. section 17.2
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
println!("{:?}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap());
}
This minimal Rust example converts the current SystemTime into a duration since UNIX_EPOCH; unwrap handles the demonstrated successful result. section 17.2
