Crates.io | millisecond |
lib.rs | millisecond |
version | 0.3.0 |
source | src |
created_at | 2024-06-27 22:32:54.334763 |
updated_at | 2024-09-17 04:52:41.718795 |
description | Format milliseconds into a human-readable format. It also, parse a milliseonds into its core parts, including years, days, hours, etc. This package has no-std dependency. |
homepage | |
repository | https://github.com/raeisimv/millisecond.git |
max_upload_size | |
id | 1286256 |
size | 27,452 |
A better way to format and display time, which converts 33023448000ms
to 1y 17d 5h 10m 48s
In your Rust project root directory run:
$ cargo add millisecond
use millisecond::Millisecond;
fn main() {
let ms = Millisecond::from_millis(33023448000);
print!("display: {ms}");
// display: 1y 17d 5h 10m 48s
print!("short: {}", ms.to_short_string());
// short: 1y 17d 5h 10m 48s
print!("long: {}", ms.to_long_string());
// long: 1 year 17 days 5 hours 10 minutes 48 seconds
assert_eq!(ms, Millisecond {
years: 1,
days: 17,
hours: 5,
minutes: 10,
seconds: 48,
millis: 0,
micros: 0,
nanos: 0,
});
}
MIT
This crate is inspired by pretty-ms
npm package.