• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Time in microseconds

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic