Does rust have some timestamp utilities?


#1

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.


#2

=) Your code is almost right already, you need just to replace DateTime with std::time::Instant:
https://doc.rust-lang.org/std/time/struct.Instant.html