How to use jFuzzyDate?

Downloading and Importing jFuzzyDate

Preparing yourself to use jFuzzyDate is quite simple. Download the lastest package. Unzip the downloaded package and copy the jfuzzydate.jar file into your project.

Declare to following imports in your java files to start:

import net.sf.jfuzzydate.FuzzyDateFormat;
import net.sf.jfuzzydate.FuzzyDateFormatter;

Formatting Distances - e.g. two minutes ago

Distances are formatted using the format(Date) method. Use this method to show distances to appointments or last modifications of documents.

FuzzyDateFormatter format = FuzzyDateFormat.getInstance();
String someDaysAgo = format.formatDistance(dateInThePast);
String inSomeDays  = format.formatDistance(dateInTheFuture);

Formatting Durations - e.g. an hour

Durations are formatted using the formatDuration(...) methods. Typically you would call this method with millisecond value. This method returns a string representing a readable duration. Use this method to visualize the time between starting and end dates or generic durations, such as cooking times, appointent durations or project lifecycle phase spans.

FuzzyDateFormatter format = FuzzyDateFormat.getInstance();
String aMinute = format.formatDuration(60000);

Formatting Foreign Languages - e.g. une heure

Each formatting method has an optional locale parameter which can be used to define the formatting language.

FuzzyDateFormatter format = FuzzyDateFormat.getInstance();
String uneHeure = format.formatDuration(3600000, Locale.FRENCH);

Translation and localization of jFuzzyDate

This topic has it's own page: Internationalization.

Custom formatting configurations

jFuzzyDate is able to be extended by custom and dynamic configurations. Have a look at net.sf.jfuzzydate.FuzzingConfiguration for implementation notes.