How to convert nanoseconds to seconds using the TimeUnit enum?

前端 未结 8 2076
小鲜肉
小鲜肉 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

    TimeUnit is an enum, so you can't create a new one.

    The following will convert 1000000000000ns to seconds.

    TimeUnit.NANOSECONDS.toSeconds(1000000000000L);
    

提交回复
热议问题