|
-
April 6th, 2010, 03:16 PM
#1
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
Last edited by peahead; April 6th, 2010 at 03:17 PM.
Reason: typo
-
April 6th, 2010, 03:44 PM
#2
Re: how do you display time correctly using System.currentTimeMillis();
 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() 
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
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
April 7th, 2010, 04:10 AM
#3
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");
-
April 7th, 2010, 02:34 PM
#4
Re: how do you display time correctly using System.currentTimeMillis();
Thank you dustu pagla - works great
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|