如何用 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

更新于: 2019-07-30

514 人次浏览

开启你的 职业生涯

完成课程获得认证

开始
广告