Humanization libraries for Java.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is even with heruan:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
humanize-time
.gitignore
LICENSE
README.adoc
pom.xml

README.adoc

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