笔记
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* 节假日与周末重叠 天数
* @param startHoliday 假期开始时间
* @param holiday 假期天数
* @param restType 休息方式 1:双休 2:周日单休
* @return
* @throws Exception
*/
private long isReapert(String startHoliday,long holiday,long restType) throws Exception{
long reatpertDay =0;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
int dayForWeek = 0;
if(holiday==1){//假期只有一天,且为双休形式,得出一天假期为星期几
Calendar c = Calendar.getInstance();
c.setTime(format.parse(startHoliday));
if(c.get(Calendar.DAY_OF_WEEK) == 1){
dayForWeek = 7;
}else{
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
}
if(restType==1){
if(dayForWeek==6||dayForWeek==7){
reatpertDay = 1;
}
}
if(restType==2){
if(dayForWeek==7){
reatpertDay = 1;
}
}
}else{
Calendar calendar = new GregorianCalendar();
calendar.setTime(format.parse(startHoliday));
for(int i=0;i<holiday;i++){
calendar.add(calendar.DATE, i);
if(calendar.get(Calendar.DAY_OF_WEEK) == 1){
dayForWeek = 7;
}else{
dayForWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
}
if(restType==1){
if(dayForWeek==6||dayForWeek==7){
reatpertDay++;
}
}
if(restType==2){
if(dayForWeek==7){
reatpertDay++;
}
}
}
}
return reatpertDay;
}
要根据项目实际情况而定