java代码 计算2021年4月25日和2020年7月8日之间间隔的天数。
时间: 2024-05-03 08:22:24 浏览: 78
用javascript实现计算两个日期的间隔天数
```java
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class DaysBetweenDates {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2021, 4, 25);
LocalDate date2 = LocalDate.of(2020, 7, 8);
long daysBetween = ChronoUnit.DAYS.between(date2, date1);
System.out.println("Days between " + date2 + " and " + date1 + ": " + daysBetween);
}
}
```
输出结果为:Days between 2020-07-08 and 2021-04-25: 291
阅读全文