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

530 Valid Hostname Is Expected When Setting Up IIS 10 For Multiple Sites

C Perror Example

Converting A String To Int In Groovy