java 当前时间获取过去4个季度时间
时间: 2024-06-14 21:06:20 浏览: 14
```java
import java.time.LocalDate;
import java.time.Month;
public class Main {
public static void main(String[] args) {
LocalDate currentDate = LocalDate.now();
int currentYear = currentDate.getYear();
Month currentMonth = currentDate.getMonth();
for (int i = 0; i < 4; i++) {
Month quarterStartMonth = currentMonth.minus(3 * i);
int quarterStartYear = currentYear; if (quarterStartMonth.getValue() <= 0) {
quarterStartMonth = quarterStartMonth.plus(12);
quarterStartYear--;
}
LocalDate quarterStartDate = LocalDate.of(quarterStartYear, quarterStartMonth, 1);
LocalDate quarterEndDate = quarterStartDate.plusMonths(3).minusDays(1);
System.out.println("Quarter " + (i + 1) + " start date: " + quarterStartDate);
System.out.println("Quarter " + (i + 1) + " end date: " + quarterEndDate);
}
}
}
```
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)