rust - 如何从现在算起 5 分钟?

标签 rust

我需要用 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/

相关文章:

rust - futures::executor::block_on 和 block_in_place 之间是否存在性能差异

unix - 如何从 Rust 写入特定的原始文件描述符?

rust - 如何按字母顺序对字符串向量进行排序?

rust - 从 HashSet 中获取具有最低值的元素?

windows - 为什么通过 FFI 接口(interface)从 Rust 调用 Ada DLL 时会卡在 adainit?

rust - 如何为通用数字类型创建特定值?

struct - 在 Rust 中将结构解包为左值元组

rust - 在没有特征(move_ref_pattern)或 mem::replace 的情况下处理具有组合移动和引用的模式的策略是什么?

loops - 你如何在 Rust 中创建一个范围?

assembly - 如何在 Rust 中跳转到/调用任意内存