Java-时间处理

1、常用实例 

package com.geekyjane.cnblogs.nanotime;
 
import java.util.concurrent.TimeUnit;
 
public class TransferToSeconds {
    public static void main(final String[] args) {
        long start = System.nanoTime();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        long period = System.nanoTime() - start;
        System.out.println(String.format(
                "period(nanoseconds): %d, period(seconds): %d", new Object[] {
                        period, TimeUnit.NANOSECONDS.toSeconds(period) }));
    }
 
}

//period(nanoseconds): 4999610094, period(seconds): 4

2、其他

//todo

 

 

参考目录:1、System.nanoTime()返回结果nanoSeconds和seconds之间的转换

 

你可能感兴趣的:(JAVA)