GeeCON Prague 2014*
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
Author

How to read system clock?

Ilya PA
Greenhorn

Joined: Aug 30, 2002
Posts: 4
Hi,
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
Greenhorn

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

System.currentTimeMillis(); might be a little easier to use. For more accurate timing see http://www.boulder.nist.gov/timefreq/service/its.htm
[ August 30, 2002: Message edited by: Dan Cranmer ]
Ilya PA
Greenhorn

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"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
ilya,
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.
Thanks,
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
GeeCON Prague 2014
 
subject: How to read system clock?