Tag Archives: System.nanoTime…

Java system. Currenttimemillis() and system. Nanotime

Nanosecond

NS (nanosecond): nanosecond,

Time unit. One billionth of a second is equal to the minus ninth power of 10. Commonly used as

A unit of memory read-write speed. The smaller the number in front of it, the faster it is.

1 nanosecond = 1000

Picosecond

1 ns = 0.001

Microsecond

1 ns = 0.00000 1

millisecond

1 nanosecond = 0.00000 0001 seconds

What is the difference between system. Currenttimemillis() and system. Nanotime() in Java

In Java, system. Nanotime() returns nanoseconds, and nanotime may return any time, or even negative numbers… According to the API, the main purpose of nanotime is to measure a period of time, such as the time for a code execution, the time for database connection, the time for network access, etc. In addition, nanotime provides nanosecond precision, but the actual value may not be accurate to nanosecond

But in general, these two functions are used for different purposes

The MS returned by system. Currenttimemillis() in Java is actually the number of MS since 0:00 on January 1, 1970. Date() is actually equivalent to date (system. Currenttimemillis()); Because the date class also constructs a date (long date) to calculate the millisecond difference between long seconds and January 1, 1970