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

Time in microseconds

Priya Kubher

Joined: Jan 07, 2003
Posts: 10
Hi all.
I am wondering how to get time in microseconds in Java. Can someone please help me out.
Thanks a lot.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
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
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

Joined: Jan 07, 2003
Posts: 10
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
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
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
To save you even a bit more time, you might want to look at this:
Greetings, Erik
I agree. Here's the link:
subject: Time in microseconds
It's not a secret anymore!