Your Computer Science Resource

Posts Tagged ‘relative time’

Aug
13th

Java Relative Date and Time

In an application I’m working on, I needed the ability to show the date and time in a relative manner. In other words, rather than displaying the full date and time like “August 13, 2009 at 3:07 pm”, I wanted to be able to determine when this date is relative to now and show this instead (e.g. “one hour ago” or “one hour from now”). The result? A simple yet useful class which converts a Calendar or Date object into a String representing the relative date.

(more…)