假设我们有以下两个日期-
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