以下是一个Java代码示例,用于获取上个季度的起始年月:

import java.time.LocalDate;
import java.time.Month;

public class Main {
  public static void main(String[] args) {
    LocalDate now = LocalDate.now();
    int quarter = (now.getMonthValue() - 1) / 3;
    int year = now.getYear();
    if (quarter == 0) {
      year--;
      quarter = 3;
    } else {
      quarter--;
    }
    Month startMonth = Month.of(quarter * 3 + 1);
    LocalDate startDate = LocalDate.of(year, startMonth, 1);
    System.out.println("上个季度的起始年月为:" + startDate.getYear() + "-" + startDate.getMonthValue());
  }
}

这个代码会获取当前日期,计算上个季度的年份和季度数,然后通过月份计算出季度的起始月份,最后构造一个LocalDate对象来表示上个季度的起始年月。

ssIm sorry could you please provide more context or information for me to understand what you mean by ss用Java获得上个季度的起始年月

原文地址: https://www.cveoy.top/t/topic/bUZU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录