#duration-human #duration #pretty

human-duration

human-duration converts a std::time::Duration to a human readable string

1 unstable release

0.1.0 Jan 17, 2022

#675 in Date and time

Download history 47/week @ 2025-09-18 78/week @ 2025-09-25 65/week @ 2025-10-02 53/week @ 2025-10-09 81/week @ 2025-10-16 70/week @ 2025-10-23 64/week @ 2025-10-30 34/week @ 2025-11-06 40/week @ 2025-11-13 34/week @ 2025-11-20 40/week @ 2025-11-27 61/week @ 2025-12-04 49/week @ 2025-12-11 74/week @ 2025-12-18 30/week @ 2025-12-25 38/week @ 2026-01-01

199 downloads per month
Used in 5 crates

MIT license

7KB
81 lines

Human-readable duration

human-duration converts a std::time::Duration to a human readable string.

Examples:

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

human-duration

Crates.io Crates.io docs.rs

human-duration converts a std::time::Duration to a human readable string.

Examples

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

Usage

Run

cargo add human_duration

or manually add it to your Cargo.toml:

[dependencies]
human_duration = "0.1"

Then use the human_duration function:

use human_duration::human_duration;

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

License

MIT

No runtime deps