http://docs.oracle.com/javase/6/docs/api/java/sql/Timestamp.html
The only non-deprecated ctor takes millis. Is there no way to ask for 'now' including nanos.
http://docs.oracle.com/javase/6/docs/api/java/sql/Timestamp.html
The only non-deprecated ctor takes millis. Is there no way to ask for 'now' including nanos.
getNanos()/setNanos(int)
on Timestamp exists to support databases that return the timestamp data type with nanosecond precision.
Java does not have a means to get the current time with nanosecond precision. System.nanoTime()
returns elapsed nanoseconds from some unknown epoch chosen by the JVM. It is useful for measuring elapsed time between two calls of System.nanoTime()
. Even then while System.nanoTime()
can measure elapsed time between calls to nanosecond precision it is not necessarily accurate to nanosecond precision as mentioned in the javadocs.
As has been noted in comments on other answers, System.nanoTime()
doesn't really return any meaningful values regarding time in nanoseconds.
I would like to point to this discussion from SO which points out why we can't get better accuracy on our time measurements. It would appear to imply that it is not really possible to do as you ask, and that it would be against some Java design goals to try and include this ability, due to portability and platform constraints.
So, in answer to your question, I would say no, but only based upon the answers of people with more rep than me.