I want to take two times (in seconds since epoch) and show the difference between the two in formats like:
- 2 minutes
- 1 hour, 15 minutes
- 3 hours, 9 minutes
- 1 minute ago
- 1 hour, 2 minutes ago
How can I accomplish this??
dateformattingjavatime
I want to take two times (in seconds since epoch) and show the difference between the two in formats like:
How can I accomplish this??
Best Answer
Since everyone shouts "YOODAA!!!" but noone posts a concrete example, here's my contribution.
You could also do this with Joda-Time. Use
Period
to represent a period. To format the period in the desired human representation, usePeriodFormatter
which you can build byPeriodFormatterBuilder
.Here's a kickoff example:
Much more clear and concise, isn't it?
This prints by now
(Cough, old, cough)