how do you display time correctly using System.currentTimeMillis();
I am using a timer routine which I obtained from the net. This is the code:
Code:
long start = System.currentTimeMillis();
textAreaGameInfo.append(strBuf.toString());
long elapsed = System.currentTimeMillis() - start;
How can I force the correct display of time as follows:
If 0 seconds or less it should show 0.142 milliseconds
If 0 seconds or greater it should show 1.42 seconds
If 1 minute or greater it should show 1min 42 seconds
Thanks
Re: how do you display time correctly using System.currentTimeMillis();
Quote:
Originally Posted by
peahead
If 0 seconds or less it should show 0.142 milliseconds
You won't get thousandths of a millisecond from System.currentTimeMillis() :D
Once you get your units/decimal places sorted out, you can use SimpleDateFormat.
Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it...
A. Aho and J. Ullman
Re: how do you display time correctly using System.currentTimeMillis();
you may use :
double start = System.currentTimeMillis();
//your program...
double stop = System.currentTimeMillis();
System.out.print((stop-start)+" Millisecond")
//or
System.out.print((stop-start)/1000+" Seconds");
Re: how do you display time correctly using System.currentTimeMillis();
Thank you dustu pagla - works great