java获取当前时间所在季度的总天数
时间: 2023-11-24 10:52:38 浏览: 109
以下是Java获取当前时间所在季度的总天数的代码示例:
```java
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
public class Main {
public static void main(String[] args) {
// 获取当前日期
LocalDate now = LocalDate.now();
// 获取当前季度的第一天
LocalDate firstDayOfQuarter = now.with(now.getMonth().firstMonthOfQuarter())
.with(TemporalAdjusters.firstDayOfMonth());
// 获取当前季度的最后一天
LocalDate lastDayOfQuarter = firstDayOfQuarter.plusMonths(2).with(TemporalAdjusters.lastDayOfMonth());
// 计算当前季度的总天数
int daysOfQuarter = lastDayOfQuarter.getDayOfMonth() - firstDayOfQuarter.getDayOfMonth() + 1;
System.out.println("当前季度的总天数为:" + daysOfQuarter);
}
}
```
运行结果:
```
当前季度的总天数为:91
```
阅读全文