Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Relative time (time since)

Thread view: 
Robert M. Gary - 06 Apr 2007 18:35 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
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();


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.