Hi all. I am wondering how to get time in microseconds in Java. Can someone please help me out. Thanks a lot. Priya
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
posted
0
Well, you could just take System.currentTimeMillis() and multiply by 1000. Seriously though, I don't think Java provides microseconds capability. Sorry.
"I'm not back." - Bill Harding, Twister
David Weitzman
Ranch Hand
Joined: Jul 27, 2001
Posts: 1365
posted
0
JSR 166 will contain a class TimeUnit which encapsulates the mind-numbing complexity of multiplication by a power of ten . It will also potentially enable fast processors to measure extremely small time intervals in microseconds or nanoseconds, but it won't give the actual solar date and time in nanoseconds. If your goal is to determine how much time has elapsed rather then to obtain the actual system time, you can wait until Java 1.5 comes out an use code that looks something like this:
Priya Kubher
Greenhorn
Joined: Jan 07, 2003
Posts: 10
posted
0
So there is no way I can measure elapsed time in microseconds as things stand now!!!
Thanks for the info. It saves me hours trying to find the right code. Maybe I will try and use Native interface to c.
Guy Allard
Ranch Hand
Joined: Nov 24, 2000
Posts: 776
posted
0
Even if the processor you are running on has a real time clock accurate in micro- or nano- seconds, the standard C library calls probably will not give that to you. If so, use JNI to call C, and in C call an Assembler program to get current clock values. In any case, you will never get more accurate than the processor's RTC. Regards, Guy