package com.company;
import java.time.Duration;
import java.time.Instant;
public class Main {
public static void main(String[] args) {
// Instant可表示的时间范围:±10亿年
Instant min = Instant.MIN;
Instant max = Instant.MAX;
Instant start = Instant.now();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Instant end = Instant.now();
// 计算两个时刻之间的时间量
Duration timeElapsed = Duration.between(start, end);
long millis = timeElapsed.toMillis();
System.out.println("Instant的时间范围:" + min + " 至 " + max);
System.out.println("时间差:" + millis);
}
}
// 构建LocalDate对象
LocalDate now = LocalDate.now();
LocalDate date1 = LocalDate.of(1903, 6, 14);
LocalDate date2 = LocalDate.of(1903, Month.JUNE, 14);
// 获取时间间隔
long until = date2.until(now, ChronoUnit.DAYS);
System.out.println(until);
原文:https://www.cnblogs.com/xl4ng/p/12851061.html