How to convert nanoseconds to seconds using the TimeUnit enum?

前端 未结 8 2086
小鲜肉
小鲜肉 2020-12-07 09:37

How to convert a value from nanoseconds to seconds?

Here\'s the code segment:

import java.io.*;
import java.util.concurrent.*; 
..

class Stamper          


        
8条回答
  •  青春惊慌失措
    2020-12-07 10:18

    To reduce verbosity, you can use a static import:

    import static java.util.concurrent.TimeUnit.NANOSECONDS;
    

    -and henceforth just type

    NANOSECONDS.toSeconds(elapsedTime);
    

提交回复
热议问题