With the maven it is just a second to have it in the project. You only add following dependency to the POM file:
<dependency> <groupid>com.ocpsoft</groupid> <artifactid>ocpsoft-pretty-time</artifactid> <version>1.0.7</version> </dependency>To format a date to a human readable value, one line of code is enough:
String prettyTimeString = new PrettyTime().format(new Date());The result is: "chwilę temu" ("moments ago"). Just as expected.
Easy to use. Fully configurable. I18n support included. Just checkout the project page: http://ocpsoft.com/prettytime and enjoy the ease of timestamp formating!
Short note: If you wish to force formatting in English (default), you need to pass locale object to the c-tor with the empty language value, like below. If you don't do this you get the output in the language of the current locale. In my case it was Polish.
String prettyTimeString = new PrettyTime(new Locale("")).format(new Date());