Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Precision time functions in Java  RSS feed

 
Parvez Pathan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need a function which gives me the system time in microseconds.
I've tried the getTime() function in the Date class, but it gives me a precision of milli seconds, which does not serve my purpose.
Please send me a solution as soon as possible.
Thanks,
Parvez
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parvez,
I know that System.currentTimeMillis() static method returns the number of milliseconds from midnight Jan 1, 1970... There is not really any way to measure a smaller time slice than a millisecond in Java (as far as I know...), and I really doubt that you could measure any unit of time smaller than a millisecond with anything other than a very specialized computer... most computers store the system time as a long integer currently (which is 32 bits... in the past, when memory was sparse, the size to store the system date was even smaller)... to store system time in smaller slices would require a number even larger than a long (which most systems do not currently provide), plus the system would have to keep track of the current time in microseconds... which I don't believe most systems currently do...
Sorry,
-Nate
P.S. - While messing around with the date class I found out that the "last day" Java will be able to realize under the current scheme is Sunday, August 17 292278994, with time "ending" at exactly 3:12:55 EDT... Oh no! It's the Y292M bug!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!