In Ruby on Rails, there is a feature that allows you to take any Date and print out how "long ago" it was.
For example:
8 minutes ago
8 hours ago
8 days ago
8 months ago
8 years ago
Is there an easy way to do this in Java?
In Ruby on Rails, there is a feature that allows you to take any Date and print out how "long ago" it was.
For example:
8 minutes ago
8 hours ago
8 days ago
8 months ago
8 years ago
Is there an easy way to do this in Java?
java.time
Using the java.time framework built into Java 8 and later.
Have you considered the TimeUnit enum? It can be pretty useful for this kind of thing
Take a look at the PrettyTime library.
It's quite simple to use:
You can also pass in a locale for internationalized messages:
As noted in the comments, Android has this functionality built into the
android.text.format.DateUtils
class.Here is my Java Implementation of this
more @Format a duration in milliseconds into a human-readable format
After long research i found this.