tags:

views:

133

answers:

2

Hi everyone, Ive created timer. How can I change the timer format to second so that it wont be long number? Thanks

private long startTime  = System.currentTimeMillis();
Timer timer  = new Timer(1000, this);
timer.start();

timer.stop();
long endTime    = System.currentTimeMillis();
long timeInMilliseconds = (endTime - startTime);
+6  A: 

divide by 1000 for seconds from milliseconds.

Chris Ballance
How could I reset the time when I click a button? I tried to use timer.reset() but it doesnt work..Thanks
Jessy
As Eddie mentioned, it may depend on which implementation of Timer you are using. If .reset() doesn't behave as you expect it, you can always just throw out the current timer and instantiate a new one.
Chris Ballance
A: 

You can define a constant SECOND and use it like this:

new Timer(1 * SECOND, this);
HappyCoder