/**
* 获取指定日期所在周的周一
*
* @param date 日期
*/
public static Date getFirstDayOfWeek(Date date) {
Calendar c = 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);
return c.getTime();
}
/**
* 获取指定日期所在周的周日
*
* @param date 日期
*/
public static Date getLastDayOfWeek(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
// 如果是周日直接返回
if (c.get(Calendar.DAY_OF_WEEK) == 1) {
return date;
}
System.out.println(c.get(Calendar.DAY_OF_WEEK));
c.add(Calendar.DATE, 7 - c.get(Calendar.DAY_OF_WEEK) + 1);
return c.getTime();
}
网友评论