Automatic user readable time interval

I would like to express some time intervals in a humanoid format. I was looking for a library that could automatically select the correct unit size. Intervals will range from milliseconds to several weeks. Something like

  • 0.2sec
  • 2 a.m.
  • 4 days
  • ...

I know that I can manually check the size of the argument and then convert it, but before reinventing the wheel, I wanted to ask if there is a (standard) library for this.

Edit

My entry in nanoseconds and exit as described above.

+7
source share
1 answer

Check PrettyTime

PrettyTime is an OpenSource time formatting library. Fully customizable, PrettyTime creates user-friendly relative timestamps, similar to those seen on Digg, Twitter and Facebook. Just start "right now!" and in more than 18 languages!

Example

PrettyTime p = new PrettyTime(); System.out.println(p.format(new Date())); //prints: "right now" PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L)); t.format(new Date(0)); //3 centuries ago 
+24
source

All Articles