TimeUnit toNanos() method in Java with Examples
The toNanos() method of TimeUnit Class is used to get the time represented by the TimeUnit object, as the number of NanoSeconds, since midnight UTC on the 1st January 1970.
public long toNanos(long duration)
Parameters: This method accepts a mandatory parameter duration which is the duration in milliSeconds.
Return Value: This method returns the converted duration as NanoSeconds.
Below program illustrate the implementation of TimeUnit toNanos() method:
Time 1539585501608 milliSeconds in NanoSeconds = 1539585501608000000
Time 1539585503771 milliSeconds in NanoSeconds = 1539585503771000000
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.