Hi,

Is there a way of timing how long it takes between a piece of code executing to when it finishes and then displaying this time? I would like to display a clock which begins timing when a program starts running and stops when it finishes.

Thanks

just add a timer at the start of the program execution .... there are two types of timers .... one for gui and one is general
general:
java.util.Timer
Timer t = new Timer();

gui:
javax.swing.*
Timer t = new Timer(ActionListener, delay);

Read more about the timers in the java API.

What you see is in milliseconds. When you get the difference, multiply by 1000 and you will have how many seconds have passed

You have a value in milliseconds. You can either use SimpleDateFormat, or do it yourself using the following rules:
1 sec = 1000 millisec
1 min = 60 sec
1 hour = 60 min

And sorry about my last post, I made a very big mistake: You must divide by 1000 to get the seconds

This article has been dead for over six months. Start a new discussion instead.