Unusual display of temporary formats "5 min. Back", "yesterday", etc.

How can you format time, for example, modern web pages (including StackOverflow ;-), for example, using simple relative descriptions, for example:

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

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

+8
java time datetime-format
source share
1 answer

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.

+10
source share

All Articles