MicroSecond in JAVA

Hi Guys,I want to log my application time stamp with microseconds.Is there any way to do it in java?
[121 byte] By [Fred_1kinga] at [2007-11-26 16:58:33]
# 1
use the result of System.nanoTime() and divide it by 1000
georgemca at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 2

that gets microsecond timestamps, but beware that will not necessarilly get you microsecond precision as the nanosecond time method doesn't guarantee nanosecond precision (depending on operating system if might get precision of 20 microseconds or worse, this is due to restrictions of the system the JVM is running on rather than the JVM itself).

To get that you'll need an external API of some sorts, probably depending on JNI code and a hardware timing device.

jwentinga at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 3
I'm sure System.currentTimeMillis() is all the OP needs here...
CarrieHunta at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 4
System.nanoTime is no way related to the system clock. Its the system timer. It wont helpe me out in this.I need the system time to get loggeg with microseconds.I dont want to go for JNI and call a c code.Is there a way?
Fred_1kinga at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 5
> I'm sure System.currentTimeMillis() is all the OP> needs here...Ah, another of your illinformed idiocies.Pray how will currentTimeMillis ever return microsecond precision?
jwentinga at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 6

> System.nanoTime is no way related to the system

> clock. Its the system timer. It wont helpe me out in

> this.

> I need the system time to get loggeg with

> microseconds.

> I dont want to go for JNI and call a c code.

> Is there a way?

no, there isn't.

You'll need external hardware to provide the required precision, and unless that hardware comes with a Java library to access it (which would use JNI internally almost certainly) you're not going to do this.

Same for other languages, those too would need an external source to provide the precision you require.

jwentinga at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 7
Last time I needed time precision I used Multimedia Timer. But I guess it is Windows-specific. This was 4 years ago and I have almost forgot what happened then;)Mike
bellyrippera at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 8

> > I'm sure System.currentTimeMillis() is all the OP

> > needs here...

>

> Ah, another of your illinformed idiocies.

> Pray how will currentTimeMillis ever return

> microsecond precision?

Microsecond precision was not requested. Just a microsecond count. Given the vagueness of the question, I'd say he currentTimeMillis() * 1000 response is valid - I'd even concur.

CeciNEstPasUnProgrammeura at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...
# 9

> Microsecond precision was not requested. Just

> a microsecond count. Given the vagueness of the

> question, I'd say he currentTimeMillis() * 1000

> response is valid - I'd even concur.

right, i also assumed the OP just needed a simple timer and so often I see people recommending insanely complex solutions when it's not necessary (such as using JNI). thanks for backing me up. and thanks jwenting for your usual cr@p, i hope it makes you feel good

CarrieHunta at 2007-7-8 23:26:20 > top of Java-index,Java Essentials,Java Programming...