Link to home
Start Free TrialLog in
Avatar of ES5
ES5

asked on

running clock

Hi, I am new to Java and i'd like some help with this little program.
I know how to get the time from the system but i dont know how to keep the time updated, i.e. the seconds ticking etc. Could some one pls help,

Much Appreciated
ASKER CERTIFIED SOLUTION
Avatar of antonsigur
antonsigur
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mayank S
At any time, you can just use:

new Date ().getTime ()

to get the time in milliseconds from Jan 1, 1970, right then. So why do you need to keep your object ticking? Whenever you need the time, just make a new object and use the method.

Mayank.
Yes he can, but he could be creating an applet wich displays time, then he needs to update the Applet's clock every second, won't he, so he could use this code to do it:

while (true) {
 //Your code to get the time and display it
 try {
   Thread.sleep(1000);
 } catch (InterruptedException e) {
    e.printStackTrace();  
 }
}
Avatar of ES5
ES5

ASKER

thanx antonsigur, the sleep function was all i needed just didnt know how to use it...

much appreciated
- good it worked for you!