No description
Find a file
Midas van Oene 8626ce9881
All checks were successful
Build and Test / build (push) Successful in 31s
Adjust documentation / Add future improvements to README.md
2026-03-24 21:48:35 +01:00
.forgejo/workflows Use the correct runner 2026-03-24 15:52:52 +01:00
src Adjust documentation / Add future improvements to README.md 2026-03-24 21:48:35 +01:00
.gitignore Initial project setup w/CI 2026-03-24 15:20:15 +01:00
pom.xml Fix CI by explicitly stating compiler source/target 2026-03-24 15:42:03 +01:00
README.md Adjust documentation / Add future improvements to README.md 2026-03-24 21:48:35 +01:00

duration-formatter

A Java library that converts millisecond durations into human-readable strings like "5 hours 3 minutes 34 seconds" or "5h 3m 34s".

Usage

Default formatter

DurationFormatter formatter = DurationFormatter.ofDefaults();
formatter.format(18214000); // "5 hours 3 minutes 34 seconds"
formatter.format(3600000);  // "1 hour 0 minutes 0 seconds"
formatter.format(1000);     // "0 hours 0 minutes 1 second"

Hiding zero values

DurationFormatter formatter = DurationFormatter.builder()
        .hideZeroValues()
        .build();
formatter.format(214000);  // "3 minutes 34 seconds"
formatter.format(3900000); // "1 hour 5 minutes"
formatter.format(0);       // "0 seconds"

Format styles

DurationFormatter formatter = DurationFormatter.builder()
        .style(FormatStyle.SHORT)
        .build();
formatter.format(18214000); // "5h 3m 34s"
formatter.format(3600000);  // "1h 0m 0s"

Combining options

DurationFormatter formatter = DurationFormatter.builder()
        .style(FormatStyle.SHORT)
        .hideZeroValues()
        .build();
formatter.format(214000);  // "3m 34s"
formatter.format(3900000); // "1h 5m"
formatter.format(0);       // "0s"

Future improvements

  • Localization — support for different languages and custom short labels via ResourceBundle
  • Additional time units — days, weeks, etc..
  • Custom format patterns — user-defined output templates