How to count 5 minutes from now?

2019-05-11 03:53发布

I need to count 5 minutes from now in Rust. I thought I could use time::now() but it's deprecated. What can I use and how to do that?

标签: rust
1条回答
放我归山
2楼-- · 2019-05-11 04:40

If you mouse over the "deprecated" note in the documentation, you'll see that it points you to the rust-lang/time repository. Basically, it got moved out of the standard library into its own package.

Provided you add a dependency on the time crate as specified in the documentation, this works:

extern crate time;

use std::time::duration::Duration;

fn main() {
    let now = time::get_time();
    println!("now:   {}", now);
    let later = now + Duration::minutes(5);
    println!("later: {}", later);
}
查看更多
登录 后发表回答