Conversion of nanoseconds to milliseconds and nanoseconds < 999999 in Java
Just take the divmod of it with 1000000.
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);