| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.Month; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | System.out.println("@AfterAll =================="); |
| | | } |
| | | |
| | | /** |
| | | * @Description TODO 获取本季度的第一天或最后一天 |
| | | * @Param: [today, isFirst: true 表示开始时间,false表示结束时间] |
| | | * @return: java.lang.String |
| | | */ |
| | | public static String getStartOrEndDayOfQuarter(LocalDate today, Boolean isFirst) { |
| | | LocalDate resDate = LocalDate.now(); |
| | | if (today == null) { |
| | | today = resDate; |
| | | } |
| | | Month month = today.getMonth(); |
| | | Month firstMonthOfQuarter = month.firstMonthOfQuarter(); |
| | | Month endMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2); |
| | | if (isFirst) { |
| | | resDate = LocalDate.of(today.getYear(), firstMonthOfQuarter, 1); |
| | | } else { |
| | | resDate = LocalDate.of(today.getYear(), endMonthOfQuarter, endMonthOfQuarter.length(today.isLeapYear())); |
| | | } |
| | | return resDate.toString(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-05-04"), false)); |
| | | System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-06-04"), false)); |
| | | System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-07-04"), false)); |
| | | System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-01-04"), false)); |
| | | System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-02-04"), false)); |
| | | } |
| | | |
| | | |
| | | } |