#duration #human #pretty

human-duration

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

1 个不稳定版本

0.1.0 2022年1月17日

#371日期和时间

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

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");

无运行时依赖