Java程序获取两个时刻之间的持续时间
创建两个时刻:
Instant time1 = Instant.now(); Instant time2 = Instant.now().plusSeconds(50);
使用between()得到两个时刻之间的时间:
long resMilli = Duration.between(time1, time2).toMillis();
示例
import java.time.Duration;
import java.time.Instant;
public class Demo {
public static void main(String[] args) {
Instant time1 = Instant.now();
Instant time2 = Instant.now().plusSeconds(50);
long resMilli = Duration.between(time1, time2).toMillis();
System.out.println("Duration between two time intervals = "+resMilli);
}
}输出结果
Duration between two time intervals = 50000
热门推荐
2 成都训练狗狗
3 怎么训练小狗狗
4 训练狗狗软件
5 如何训练狗狗拉屎
9 狗狗负重训练
10 狗狗多大可以训练大小便
11 怎么训练狗狗萨摩耶
12 狗狗训练书
13 鞍山狗狗训练
14 训练狗狗用品
15 怎样才能训练狗狗听话
16 狗狗如何训练大小便
17 怎样训练狗狗睡狗窝
18 训练狗狗工具