Relative time (time since)

R

Robert M. Gary

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
 
D

Daniel Pitts

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

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top