关于空闲时间的计算
public class FreeTimeInteval {
static List<Date> timeList = new ArrayList<Date>();
static {
timeList.add(new Date("2024/5/1"));
timeList.add(new Date("2024/5/5"));
timeList.add(new Date("2024/5/9"));
timeList.add(new Date("2024/5/14"));
timeList.add(new Date("2024/5/18"));
timeList.add(new Date("2024/5/24"));
timeList.add(new Date("2024/5/27"));
timeList.add(new Date("2024/5/30"));
}
public static List<Date> calculateFreeTime(){
Date tempTime = null;
List<Date> tempTimeList = new ArrayList<Date>();
for (int i = 0; i < timeList.size(); i++) {
Date currentTime = timeList.get(i);
if (i != 0 && tempTime != null){
if ((DateUtil.calcDateBalance(tempTime, currentTime) / (24 * 60 * 60 * 1000)) > 2 && (i%2 == 0)){
tempTimeList.add(tempTime);
tempTimeList.add(currentTime);
}
}
tempTime = currentTime;
}
return tempTimeList;
}
public static void main(String[] args) {
System.out.println(calculateFreeTime());
}
}