本文共 1942 字,大约阅读时间需要 6 分钟。
map = new HashMap();
long reapertdays = 0;//重叠天数
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 标准时间
Date bt = sdf.parse(startPlans);
Date ot = sdf.parse(endPlans);
// 目标时间
Date st = sdf.parse(startHoliday);
Date ed = sdf.parse(endHoliday);
long btlong = Math.min(bt.getTime(), ot.getTime());// 开始时间
long otlong = Math.max(bt.getTime(), ot.getTime());// 结束时间
long stlong = Math.min(st.getTime(), ed.getTime());// 开始时间
long edlong = Math.max(st.getTime(), ed.getTime());// 结束时间
if ((stlong >= btlong && stlong <= otlong) || (edlong >= btlong && edlong <= otlong)) {
// 一定有重叠部分
long sblong = stlong >= btlong ? stlong : btlong;
long eblong = otlong >= edlong ? edlong : otlong;
String sblongs = sdf.format(sblong);
String eblongs = sdf.format(eblong);
Date d1=sdf.parse(sblongs);
Date d2=sdf.parse(eblongs);
String ds1 = sdf.format(d1);
String ds2 = sdf.format(d2);
reapertdays=((d2.getTime()-d1.getTime())/(3600*24*1000))+1;//重叠天数
map.put("reapertdays", reapertdays);
map.put("Ds1", ds1);
map.put("Ds2", ds2);
return map;
}
map.put("reapertdays", reapertdays);
return map;
}
/**
* 节假日与周末重叠 天数
* @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();
for(int i=0;iEW)//给定的星期几大于结束日期的星期几,需要减少一天
sunDay--;
}catch(Exception se){
se.printStackTrace();
}
return sunDay;
}
}
转载地址:http://elvqa.baihongyu.com/