Reputation: 8397
So I have an ISO 8601 date/time stamp like "2011-04-21T17:07:50-07:00", and I would like to convert it to say something like "23 minutes ago" or something of that sort. Is there a small bit of Java code or a library that would be able to do something like that easily?
Thanks!
Upvotes: 0
Views: 1492
Reputation: 5117
What you are looking for is known as fuzzy time. A quick Google on this term found jFuzzyDate
Upvotes: 3
Reputation: 1625
Joda is a great time library and should have all the methods you need to do this: http://joda-time.sourceforge.net/.
Upvotes: 0
Reputation:
First, parse it into a Date object. Then, make a new Date which will have the current date/time. Then, call the .getTime()
methods on both of the Date objects, and subtract. Now you have your time in milliseconds.
You can do your own math from there, because until you start worrying about leap years it's all easy division.
Upvotes: 2