Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Elapsed Time since Program Started

Status
Not open for further replies.

WindUp

Programmer
Mar 6, 2003
100
0
0
US
How do I display an Elapsed Time since the program started?

I have four Java books and I searched through all of them, and nothing indicates how to find a difference between two times. I simply want to display Hours:Minutes:Seconds elapsed.


Good Luck! [thumbsup2]
WindUp
 
Howdy from Canada.
J2ME has a 'Time' class. What you have to do is declare a variable in the constructor of your midlet, and initialize it to the system time. When you want a snapshot of the time-elapsed, initalize a second variable with the system time. Subtract the inital time from the current time, and you have the elapsed time. This needs to be converted from milli-seconds to be readable.
(You can find a reference to this in "J2ME in a Nutshell".
Luck.
-D.
 

Code:
long start = System.currentTimeMillis();

// ... processing code

long end = (start - System.currentTimeMillis());

java.util.Date time = new java.util.Date(end);
// .. use the standard methods of Date to get your seconds, minutes, hours etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top