jFuzzyDate is a Java library that converts dates, times and durations into human-readable, internationalized strings.
Maven:
<dependency>
<groupId>io.github.amaasch</groupId>
<artifactId>jfuzzydate</artifactId>
<version>0.3.0</version>
</dependency>Gradle:
dependencies {
implementation 'io.github.amaasch:jfuzzydate:0.3.0'
}The coordinates and root package changed in 0.3.0:
| 0.2.x | 0.3.0 | |
|---|---|---|
| groupId | net.sf.jfuzzydate |
io.github.amaasch |
| package | net.sf.jfuzzydate.* |
io.github.amaasch.jfuzzydate.* |
Update your dependency coordinates and replace net.sf.jfuzzydate with io.github.amaasch.jfuzzydate in your imports. No source-level API changes.
FuzzyDateFormatterImpl fmt = new FuzzyDateFormatterImpl(DefaultFuzzingConfiguration.getInstance());
// formatDuration — how long a span of time is
fmt.formatDuration(30 * 1000, Locale.ENGLISH); // "a minute"
fmt.formatDuration(60 * 2 * 1000, Locale.ENGLISH); // "two minutes"
fmt.formatDuration(60 * 35 * 1000, Locale.ENGLISH); // "35 minutes"
fmt.formatDuration(SECONDS_DAY * 1000, Locale.ENGLISH); // "a day"
// formatDistance — how far a date is from now
long now = new Date().getTime();
fmt.formatDistance(new Date(now - 90 * 1000), Locale.ENGLISH); // "a minute ago"
fmt.formatDistance(new Date(now + 3 * 3600 * 1000), Locale.GERMAN); // "in 3 Stunden"25 locales ship out of the box:
| Locale | Language | Plural rule |
|---|---|---|
en (default) |
English | TWO_FORMS_1 |
cs |
Czech | RULE8 |
da |
Danish | TWO_FORMS_1 |
de |
German | TWO_FORMS_1 |
el |
Greek | TWO_FORMS_1 |
es |
Spanish | TWO_FORMS_1 |
fr |
French | TWO_FORMS_2 |
hr |
Croatian | RULE7 |
it |
Italian | TWO_FORMS_1 |
ja |
Japanese | ASIAN |
ko |
Korean | ASIAN |
nb |
Norwegian Bokmål | TWO_FORMS_1 |
nl |
Dutch | TWO_FORMS_1 |
pl |
Polish | RULE9 |
pt |
Portuguese | TWO_FORMS_1 |
pt_BR |
Brazilian Portuguese | TWO_FORMS_2 |
ro |
Romanian | RULE5 |
ru |
Russian | RULE7 |
sk |
Slovak | RULE8 |
sr |
Serbian | RULE7 |
sv |
Swedish | TWO_FORMS_1 |
tr |
Turkish | ASIAN |
uk |
Ukrainian | RULE7 |
zh |
Chinese (Simplified) | ASIAN |
zh_TW |
Chinese (Traditional) | ASIAN |
Any unsupported locale falls back to English automatically.
jFuzzyDate is released under the GNU Lesser General Public License (LGPL).
Copyright (C) 2020 jFuzzyDate.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.