| | |
| | | package me.zhengjie.modules.quartz.utils; |
| | | |
| | | import io.swagger.models.auth.In; |
| | | import me.zhengjie.utils.StringUtils; |
| | | |
| | | import java.sql.Timestamp; |
| | |
| | | * 获取当月所有日期 |
| | | * @return |
| | | */ |
| | | public static List<String> getDayByMonth(){ |
| | | public static List<String> getDayByMonth(String yearStr, String monthStr){ |
| | | List<String> data = new ArrayList<>(); |
| | | try { |
| | | Calendar c = Calendar.getInstance(); |
| | | // 获取当前的年份 |
| | | int year = c.get(Calendar.YEAR); |
| | | c.set(Calendar.YEAR, Integer.valueOf(yearStr)); |
| | | // 获取当前的月份(需要加1才是现在的月份) |
| | | int month = c.get(Calendar.MONTH) + 1; |
| | | c.set(Calendar.YEAR, Integer.valueOf(monthStr) - 1); |
| | | // 获取本月的总天数 |
| | | int dayCount = c.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | // 定义时间格式 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 开始日期为当前年月拼接1号 |
| | | Date startDate = sdf.parse(year + "-" + month + "-01"); |
| | | Date startDate = sdf.parse(yearStr + "-" + monthStr + "-01"); |
| | | // 结束日期为当前年月拼接该月最大天数 |
| | | Date endDate = sdf.parse(year + "-" + month + "-" + dayCount); |
| | | Date endDate = sdf.parse(yearStr + "-" + monthStr + "-" + dayCount); |
| | | // 设置calendar的开始日期 |
| | | c.setTime(startDate); |
| | | // 当前时间小于等于设定的结束时间 |