Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Relative time (time since)

0 views
Skip to first unread message

Robert M. Gary

unread,
Apr 6, 2007, 1:35:08 PM4/6/07
to
Any suggestion on the best way to track relative time (mm:ss since
something happened)? I have the Date object of the begining time and
the current Date object. However, I don't see anyway to get a diff of
the Date objects (UNIX had a timediff method). I want to display as
mm:ss.

-Robert

Daniel Pitts

unread,
Apr 6, 2007, 3:19:47 PM4/6/07
to

If you have a choice, it would probably be better to use
System.currentTimeMillis()
final long before = System.currentTimeMillis();
doStuff();
final long after = System.currentTimeMillis();
final long duration = after - before;

However, if you only have access to the Date objects:
final Date dateBefore = new Date();
doStuff();
final Date dateAfter = new Date();
final long duration = dateAfter.getTime() - dateBefore.getTime();

0 new messages