| 1 | # compound_duration |
| 2 | |
| 3 | [](https://crates.io/crates/compound_duration) |
| 4 | [](https://travis-ci.org/nbari/compound_duration) |
| 5 | |
| 6 | Convert seconds to compound duration (week, days, hours, minutes, seconds) |
| 7 | |
| 8 | | input number | output string | |
| 9 | | ------------ | ------------- | |
| 10 | | 7259 | 2h59s | |
| 11 | | 86400 | 1d | |
| 12 | | 6000000 | 9w6d10h40m | |
| 13 | | 4294967295 | 7101w3d6h28m15s | |
| 14 | |
| 15 | |
| 16 | `format_dhms` or `format_wdhms`, example: |
| 17 | |
| 18 | ```rust |
| 19 | use compound_duration::format_dhms; |
| 20 | use std::time::Instant; |
| 21 | |
| 22 | fn main() { |
| 23 | let now = Instant::now(); |
| 24 | // do something ... |
| 25 | println!("{}", format_dhms(now.elapsed().as_secs())); |
| 26 | } |
| 27 | ``` |
| 28 | |
| 29 | If need nanoseconds use `format_ns`: |
| 30 | |
| 31 | ```rust |
| 32 | use compound_duration::format_ns; |
| 33 | use std::time::Instant; |
| 34 | |
| 35 | fn main() { |
| 36 | let now = Instant::now(); |
| 37 | // do something ... |
| 38 | println!("{}", format_ns(now.elapsed().as_nanos())); |
| 39 | } |
| 40 | ``` |