Whi*_*g34 19
只是System.currentTimeMillis()用来捕捉活动开始和停止的时间.例如:
long startTime = System.currentTimeMillis();
// wait for activity here
long endTime = System.currentTimeMillis();
long seconds = (endTime - startTime) / 1000;
Run Code Online (Sandbox Code Playgroud)
从Java 8开始,有一种更方便的方法。
Instant start = Instant.now();
...
Duration.between(start, Instant.now())
Run Code Online (Sandbox Code Playgroud)
这种方法的好处是Duration类提供了更灵活的API。
https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html
| 归档时间: |
|
| 查看次数: |
16040 次 |
| 最近记录: |