我需要用 Rust 从现在开始数 5 分钟。我以为我可以使用 time::now()
但它已被弃用。我可以使用什么以及如何使用?
最佳答案
如果将鼠标悬停在文档中的“已弃用”注释上,您会看到它指向 the rust-lang/time
repository .基本上,它已从标准库中移出到自己的包中。
如果您按照文档中的说明添加对 time
crate 的依赖,这将起作用:
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);
}
关于rust - 如何从现在算起 5 分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27221193/