转载:https://www.jianshu.com/p/b3bdd6c34e66
/**
* 获取指定日期所在周的周一
*
* @param date 日期
*/publicstaticDategetFirstDayOfWeek(Datedate){Calendarc=Calendar.getInstance();c.setTime(date);if(c.get(Calendar.DAY_OF_WEEK)==1){c.add(Calendar.DAY_OF_MONTH,-1);}c.add(Calendar.DATE,c.getFirstDayOfWeek()-c.get(Calendar.DAY_OF_WEEK)+1);returnc.getTime();}
/**
* 获取指定日期所在周的周日
*
* @param date 日期
*/publicstaticDategetLastDayOfWeek(Datedate){Calendarc=Calendar.getInstance();c.setTime(date);// 如果是周日直接返回if(c.get(Calendar.DAY_OF_WEEK)==1){returndate;}System.out.println(c.get(Calendar.DAY_OF_WEEK));c.add(Calendar.DATE,7-c.get(Calendar.DAY_OF_WEEK)+1);returnc.getTime();}