#duration #human #pretty

human-duration

human-duration 将 std::time::Duration 转换为人类可读的字符串

1 个不稳定版本

0.1.0 2022年1月17日

#371日期和时间

Download history • Rust 包仓库 52/week @ 2024-03-25 • Rust 包仓库 74/week @ 2024-04-01 • Rust 包仓库 43/week @ 2024-04-08 • Rust 包仓库 31/week @ 2024-04-15 • Rust 包仓库 23/week @ 2024-04-22 • Rust 包仓库 42/week @ 2024-04-29 • Rust 包仓库 40/week @ 2024-05-06 • Rust 包仓库 51/week @ 2024-05-13 • Rust 包仓库 47/week @ 2024-05-20 • Rust 包仓库 40/week @ 2024-05-27 • Rust 包仓库 64/week @ 2024-06-03 • Rust 包仓库 55/week @ 2024-06-10 • Rust 包仓库 142/week @ 2024-06-17 • Rust 包仓库 51/week @ 2024-06-24 • Rust 包仓库 14/week @ 2024-07-08 • Rust 包仓库

218 每月下载量
5 crates 中使用

MIT 许可证

7KB
81

human-duration

Crates.io Crates.io docs.rs

human-duration 将 std::time::Duration 转换为人类可读的字符串。

示例

use human_duration::human_duration;

let duration = std::time::Duration::new(120, 30_000_000);
assert_eq!(human_duration(&duration), "2m 0s 30ms");

let duration = std::time::Duration::new(9000, 0);
assert_eq!(human_duration(&duration), "2h 30m 0s 0ms");

用法

运行

cargo add human_duration

或手动添加到您的 Cargo.toml

[dependencies]
human_duration = "0.1"

然后使用 human_duration 函数

use human_duration::human_duration;

// somewhere in your code:
let duration = std::time::Duration::new(120, 0);
println!(human_duration(&duration));

许可证

MIT


lib.rs:

人类可读的持续时间

human-duration 将 std::time::Duration 转换为人类可读的字符串。

示例

use human_duration::human_duration;

let duration = std::time::Duration::new(120, 30_000_000);
assert_eq!(human_duration(&duration), "2m 0s 30ms");

let duration = std::time::Duration::new(9000, 0);
assert_eq!(human_duration(&duration), "2h 30m 0s 0ms");

无运行时依赖