|
@ -945,4 +945,127 @@ public class DateUtils { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 获取工作日时间【没有排除节假日】 |
|
|
|
|
|
* @param startDate |
|
|
|
|
|
* @param num |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/1/7 10:51 上午 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static Date getWorkDay(Date startDate, int num) { |
|
|
|
|
|
Date tomorrow = null; |
|
|
|
|
|
int delay = 1; |
|
|
|
|
|
while (delay <= num) { |
|
|
|
|
|
tomorrow = getTomorrow(startDate); |
|
|
|
|
|
if (!isWeekend(tomorrow)) { |
|
|
|
|
|
delay++; |
|
|
|
|
|
} |
|
|
|
|
|
startDate = tomorrow; |
|
|
|
|
|
} |
|
|
|
|
|
return startDate; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 根据开始时间计算出 当前日期后n个工作日【没有排除节假日】包括今天 |
|
|
|
|
|
* @param startDate |
|
|
|
|
|
* @param num |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/1/7 10:20 上午 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static List<String> getWorkDayList(Date startDate, int num) { |
|
|
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
|
|
Calendar rightNow = Calendar.getInstance(); |
|
|
|
|
|
rightNow.setTime(startDate); |
|
|
|
|
|
rightNow.add(Calendar.DATE,-1); |
|
|
|
|
|
startDate = rightNow.getTime(); |
|
|
|
|
|
Date tomorrow; |
|
|
|
|
|
Integer tag = 1; |
|
|
|
|
|
while (tag <= num){ |
|
|
|
|
|
tomorrow = getTomorrow(startDate); |
|
|
|
|
|
// 返回工作日
|
|
|
|
|
|
if (!isWeekend(tomorrow)) { |
|
|
|
|
|
result.add(new SimpleDateFormat(DATE_PATTERN).format(tomorrow)); |
|
|
|
|
|
tag++; |
|
|
|
|
|
} |
|
|
|
|
|
startDate = tomorrow; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 根据开始时间计算出 当前日期后n个周末【没有排除节假日】包括今天 |
|
|
|
|
|
* @param startDate |
|
|
|
|
|
* @param num |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/1/7 10:20 上午 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static List<String> getWeekendDayList(Date startDate, int num) { |
|
|
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
|
|
Calendar rightNow = Calendar.getInstance(); |
|
|
|
|
|
rightNow.setTime(startDate); |
|
|
|
|
|
rightNow.add(Calendar.DATE,-1); |
|
|
|
|
|
startDate = rightNow.getTime(); |
|
|
|
|
|
Date tomorrow; |
|
|
|
|
|
Integer tag = 1; |
|
|
|
|
|
while (tag <= num){ |
|
|
|
|
|
tomorrow = getTomorrow(startDate); |
|
|
|
|
|
// 返回周末
|
|
|
|
|
|
if (isWeekend(tomorrow)) { |
|
|
|
|
|
result.add(new SimpleDateFormat(DATE_PATTERN).format(tomorrow)); |
|
|
|
|
|
tag++; |
|
|
|
|
|
} |
|
|
|
|
|
startDate = tomorrow; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 根据开始时间计算出 当前日期后n天【没有排除节假日】包括今天 |
|
|
|
|
|
* @param startDate |
|
|
|
|
|
* @param num |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/1/7 10:20 上午 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static List<String> getEveryDayList(Date startDate, int num) { |
|
|
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
|
|
Calendar rightNow = Calendar.getInstance(); |
|
|
|
|
|
rightNow.setTime(startDate); |
|
|
|
|
|
rightNow.add(Calendar.DATE,-1); |
|
|
|
|
|
startDate = rightNow.getTime(); |
|
|
|
|
|
Date tomorrow; |
|
|
|
|
|
Integer tag = 1; |
|
|
|
|
|
while (tag <= num){ |
|
|
|
|
|
tomorrow = getTomorrow(startDate); |
|
|
|
|
|
result.add(new SimpleDateFormat(DATE_PATTERN).format(tomorrow)); |
|
|
|
|
|
tag++; |
|
|
|
|
|
startDate = tomorrow; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 判断日期字符串是否为周末 |
|
|
|
|
|
* @param date eg:yyyy-MM-dd |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/1/7 10:50 上午 |
|
|
|
|
|
*/ |
|
|
|
|
|
private static boolean isWeekend(Date date) { |
|
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
|
|
cal.setTime(date); |
|
|
|
|
|
return cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 获取tomorrow的日期 |
|
|
|
|
|
* @param startDate |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/1/7 10:50 上午 |
|
|
|
|
|
*/ |
|
|
|
|
|
private static Date getTomorrow(Date startDate) { |
|
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
|
|
cal.setTime(startDate); |
|
|
|
|
|
cal.add(Calendar.DAY_OF_MONTH, +1); |
|
|
|
|
|
return cal.getTime(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|