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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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();
}
}
while (true) {
//Your code to get the time and display it
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
ASKER
thanx antonsigur, the sleep function was all i needed just didnt know how to use it...
much appreciated
much appreciated
- good it worked for you!
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.