• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time in microseconds

 
Priya Kubher
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could just take System.currentTimeMillis() and multiply by 1000.
Seriously though, I don't think Java provides microseconds capability. Sorry.
 
David Weitzman
Ranch Hand
Posts: 1365
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To save you even a bit more time, you might want to look at this:
http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html
Greetings, Erik
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic