View Single Post
  #1 (permalink)  
Old 07-16-2007, 07:08 PM
paul paul is offline
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
Problem with timer in java
I would like to time (and display) how long it takes my program to preform a certain task...
Actually, I have already accomplished this but with one issue:
Code:
my timer is displayed in a label 00:00:00 when I start the timer the first second appears like this: 09:00:00 then: 09:00:01 then: 09:00:02 then: 09:00:03 ... ... ...
And seems to work fine.

Why is the first second displayed as being 9 hours long? How do I correct this issue?

Code:
long count = 0; private final SimpleDateFormat TIME = new SimpleDateFormat("hh:mm:ss"); Timer stopWatch = new Timer(1000, new ActionListener(){ public void actionPerformed(ActionEvent event){ timerDisplay.setText(TIME.format(new Date(count++ * 1000))); } });
Thanks.
Reply With Quote
Sponsored Links