arnbak / humanize

Humanization libraries for Java.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Humanization libraries for Java

humanize total humanize humanize humanize

humanize-time

humanize time

Add the dependency to your pom.xml:

<dependency>
    <groupdId>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時間前"

About

Humanization libraries for Java.

License:Apache License 2.0


Languages

Language:Java 100.0%