8

What is the best way to format time like modern web-pages (including StackOverflow ;-) do, i.e. using simple relative descriptions like:

  • 5 seconds ago
  • 23 minutes ago
  • yesterday
  • 2 days ago
  • ...

I am looking for a library that can handle this in addition to multiple locales. I can supply the phrases ( "X seconds" in English, "X Sekunden" in German etc.).

Queequeg
  • 2,824
  • 8
  • 39
  • 66
  • Tale a look here: http://stackoverflow.com/questions/2179644/how-to-calculate-elapsed-time-from-now-with-joda-time – NilsH Mar 26 '13 at 08:09

1 Answers1

10

I think this is what you are looking for :

How to calculate "time ago" in Java?

The lib: PrettyTime

For German:

PrettyTime p = new PrettyTime(new Locale("de"));
System.out.println(p.format(new Date()));

For English:

PrettyTime p = new PrettyTime();
System.out.println(p.format(new Date()));

Apparently available in 25 languages.

Community
  • 1
  • 1
Michaël
  • 3,679
  • 7
  • 39
  • 64