package com.kq.guava.stopwatch;

import com.google.common.base.Stopwatch;

import java.util.concurrent.TimeUnit;

/**
* Created by kq on 18/9/29.
*/
public class StopWatchDemo {

public static void main(String[] args) throws InterruptedException {
//start
Stopwatch stopwatch = Stopwatch.createStarted();
TimeUnit.SECONDS.sleep(3);
System.out.println(stopwatch.stop());

//重置
stopwatch.reset();
//启动
stopwatch.start();
TimeUnit.MILLISECONDS.sleep(10);
System.out.println(stopwatch.stop());

stopwatch.reset();
stopwatch.start();
TimeUnit.SECONDS.sleep(1);
//转化为毫秒
System.out.println(stopwatch.elapsed(TimeUnit.MILLISECONDS));
//转化为秒
System.out.println(stopwatch.elapsed(TimeUnit.SECONDS));


}

}