Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.74 KB

README.adoc

File metadata and controls

45 lines (36 loc) · 1.74 KB

Humanization libraries for Java

humanize total humanize humanize humanize

humanize-time

humanize time

Add the dependency to your pom.xml:

<dependency>
    <groupId>to.lova.humanize</groupId>
    <artifactId>humanize-time</artifactId>
    <version>0.1.2</version>
</dependency>

Use it in your code as simple as:

Temporal minutesAgo = ZonedDateTime.now().minus(5, ChronoUnit.MINUTES);
String relative = HumanizeTime.fromNow(minutesAgo);
// produces: "5 minutes ago"

By default it uses the locale provided by Locale.getDefault(), but you can request a different one or provide your own resolver:

Temporal minutesAgo = ZonedDateTime.now().minus(5, ChronoUnit.MINUTES);
Locale.setDefault(Locale.ITALIAN);
String italian = HumanizeTime.fromNow(temporal);
// produces: "5 minuti fa"
String french = HumanizeTime.fromNow(temporal, Locale.FRENCH);
// produces: "il y a 5 minutes"
String japanese = HumanizeTime.fromNow(temporal, () -> Locale.JAPANESE);
// produces: "5時間前"