Does rust have some timestamp utilities?

How can I create a timestamp and look for elapsed time after?

fn main() {
    let stamp = DateTime::new();
    thread::sleep(Duration::from_secs(5));
    let elapsed = DateTime::elapsed(stamp);
    println!("Elapsed time: {}", elapsed.secs().to_string()); // prints "Elapsed time: 5"
}

Please note, the code is not valid, I just ask for tools/libs which can help me to have the code like that.

=) Your code is almost right already, you need just to replace DateTime with std::time::Instant:

1 Like