• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving System Time in Micro Seconds  RSS feed

 
gadipe kris
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As part of my project, I need to retrive the System time in micro seconds,

but in java there is only one method in the System class. ie.

java.lang.System.TimeInMillis() which returns the time in milliseconds.

I need to retrieve the time in micro seconds.

Pls suggest me some solution.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds more like your typical requirement defect.
Answer: don't use a chisel to put a nail into timber, and don't use Java for real-time software applications.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also retrieve the time in nanoseconds using the System.nanoTime() method (new to JDK 1.5). However, be sure to read the notes from the API docs first:

public static long nanoTime()

Returns the current value of the most precise available system timer, in nanoseconds.
This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not accurately compute elapsed time due to numerical overflow.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!