如何用 Java 获取两个日期之间的季度数
假设我们有以下两个日期 -
LocalDate.of(2019, 3, 20); LocalDate.of(2019, 10, 25);
要获取这两个日期之间的季度数,请使用 QUARTER_YEARS -
IsoFields.QUARTER_YEARS.between(LocalDate.of(2019, 3, 20),LocalDate.of(2019, 10, 25));
示例
import java.time.LocalDate; import java.time.temporal.IsoFields; public class Demo { public static void main(String[] args) { long quarters = IsoFields.QUARTER_YEARS.between(LocalDate.of(2019, 3, 20), LocalDate.of(2019, 10, 25)); System.out.println("Quarters between the two dates = " + quarters); } }
输出
Quarters between the two dates = 2
广告