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.
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.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.