Conversion Of Nanoseconds To Milliseconds And Nanoseconds < 999999 In Java


Answer :

Why not use the built in Java methods. The TimeUnit is part of the concurrent package so built exactly for you needs



  long durationInMs = TimeUnit.MILLISECONDS.convert(delayNS, TimeUnit.NANOSECONDS);


For an ever shorter conversion using java.util.concurrent.TimeUnit, equivalent to what Shawn wrote above, you can use:



    long durationInMs = TimeUnit.NANOSECONDS.toMillis(delayNS);


Just take the divmod of it with 1000000.



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable