Transfer from https://my.oschina.net/20076678/blog/80592
What is the difference between Java's System.currenttimemillis () and System.nanotime ()
In Java, System.nanotime () returns a nanosecond, Nanotime and may return any time, or even a negative number ... According to the API, themain purpose of nanotime is to measure a time period , such as the time spent executing a code, the time it takes to get a database connection, the time it takes to access the network, and so on. In addition, Nanotime provides nanosecond-level accuracy, but the actual value obtained may not be accurate to nanoseconds.
But in general, the purpose of these two functions is completely different!.
In Java, System.currenttimemillis () returns the milliseconds, which is actually the number of milliseconds since 0 o'clock January 1, 1970, and date () is actually the equivalent of date (System.currenttimemillis ()); Because the date class has a constructed date (long date), it is used to calculate the millisecond difference between long and January 1, 1970.
Java System.currenttimemillis () and System.nanotime ()