| | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * LocalDateTimeUtils |
| | |
| | | return dayOfWeek.getValue(); |
| | | } |
| | | |
| | | /** |
| | | * 根据输入本周的周几,获取当天的时间 |
| | | * @param dayOfWeekInput 周几 |
| | | * @return |
| | | */ |
| | | public static Date getDateOfWeekNum(int dayOfWeekInput){ |
| | | // 获取当前日期 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | |
| | | // 设置为本周的第一天(星期一) |
| | | calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); |
| | | |
| | | // 根据输入的星期几数值,计算出相应的偏移量 |
| | | int dayOfWeekIndex = (dayOfWeekInput + 6) % 7; |
| | | calendar.add(Calendar.DAY_OF_WEEK, dayOfWeekIndex); |
| | | |
| | | // 获取计算后的日期 |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | |
| | | } |