Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heruan/humanize
Humanization libraries for Java.
https://github.com/heruan/humanize
i18n java time
Last synced: about 1 month ago
JSON representation
Humanization libraries for Java.
- Host: GitHub
- URL: https://github.com/heruan/humanize
- Owner: heruan
- License: apache-2.0
- Created: 2017-07-27T08:16:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-13T01:35:28.000Z (about 4 years ago)
- Last Synced: 2024-10-05T11:14:38.231Z (about 1 month ago)
- Topics: i18n, java, time
- Language: Java
- Size: 26.4 KB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Humanization libraries for Java
image:https://img.shields.io/github/release/heruan/humanize.svg[link=https://github.com/heruan/humanize/releases,title=Latest release]
image:https://img.shields.io/github/downloads/heruan/humanize/total.svg[link=https://github.com/heruan/humanize/archive/master.zip,title=GitHub]
image:https://img.shields.io/circleci/project/github/heruan/humanize.svg[link=https://circleci.com/gh/heruan/humanize,title=CricleCI]
image:https://img.shields.io/codecov/c/github/heruan/humanize.svg[link=https://codecov.io/gh/heruan/humanize,title=Codecov]
image:https://img.shields.io/github/license/heruan/humanize.svg[link=http://www.apache.org/licenses/LICENSE-2.0.html,title=Apache License 2.0]== humanize-time
image:https://img.shields.io/maven-central/v/to.lova.humanize/humanize-time.svg[title=humanize-time]
Add the dependency to your `pom.xml`:
[source,xml]
----to.lova.humanize
humanize-time
0.1.2----
Use it in your code as simple as:
[source,java]
----
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:
[source,java]
----
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時間前"
----