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 - 06 Apr 2007 20:19 GMT
> 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
[quoted text clipped - 3 lines]
>
> -Robert
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();