File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to read system clock? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to read system clock?" Watch "How to read system clock?" New topic

How to read system clock?

Ilya PA

Joined: Aug 30, 2002
Posts: 4
I'm wrighting a program that requires accurate readings from the system clock... is there an way to do it? I was trying to use the java.util.Calendar class, as follows:
Calendar clock=Calendar.getInstance();
long time=clock.getTimeInMillis();
But if i try to check the time in the same method again it gives me the same result... How come? Is there a way to overcome this?
Dan Cranmer

Joined: May 24, 2000
Posts: 24
It works for me?

System.currentTimeMillis(); might be a little easier to use. For more accurate timing see
[ August 30, 2002: Message edited by: Dan Cranmer ]
Ilya PA

Joined: Aug 30, 2002
Posts: 4
Thanx alot, that bit of code was of great help~! It pointed me out my mistake of getting only one instance of calendar and then enquiring it for time, but i should have gotten a new instance each time!
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: How to read system clock?
It's not a secret anymore!