How to calculate “time ago” in Java?

Take a look at the PrettyTime library. It’s quite simple to use: import org.ocpsoft.prettytime.PrettyTime; PrettyTime p = new PrettyTime(); System.out.println(p.format(new Date())); // prints “moments ago” You can also pass in a locale for internationalized messages: PrettyTime p = new PrettyTime(new Locale(“fr”)); System.out.println(p.format(new Date())); // prints “à l’instant” As noted in the comments, Android has this … Read more

PHP How to find the time elapsed since a date time? [duplicate]

Most of the answers seem focused around converting the date from a string to time. It seems you’re mostly thinking about getting the date into the ‘5 days ago’ format, etc.. right? This is how I’d go about doing that: $time = strtotime(‘2010-04-28 17:25:43’); echo ‘event happened ‘.humanTiming($time).’ ago’; function humanTiming ($time) { $time = … Read more