I would like to express some time intervals in a human readable format. I was looking for a library automatically able to choose the correct size of the units. The intervals will range from milliseconds to weeks. Something like
I know I could 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 to achieve that.
Edit:
My input in in nanoseconds and output as described above.
Check PrettyTime
PrettyTime is an OpenSource time formatting library. Completely customizable, PrettyTime creates human readable, relative timestamps like those seen on Digg, Twitter, and Facebook. It’s simple, get started “right now!” and in over 18 languages!
For 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With