从现在开始的 5 分钟如何计算? [英] How to count 5 minutes from now?
本文介绍了从现在开始的 5 分钟如何计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 Rust 中计算 5 分钟.我以为我可以使用 time::now()
但它已被弃用.我可以使用什么以及如何使用?
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-lang/time
存储库.基本上,它已经从标准库中移到了自己的包中.
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.
如果您按照文档中的指定添加对 time
箱的依赖,则此方法有效:
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);
}
这篇关于从现在开始的 5 分钟如何计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文