获取本周一
public static Date getNowWeekMonday(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, -1); //解决周日会出现 并到下一周的情况
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
303 return cal.getTime();
}
获取上周一
public static Date getLastWeekMonday(Date date) {
Date a = DateUtils.addDays(date, -1);
Calendar cal = Calendar.getInstance();
cal.setTime(a);
cal.add(Calendar.WEEK_OF_YEAR, -1);// 一周
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return cal.getTime();
}
获取上周日
public static Date getLastWeekSunday(Date date) {
Date a = DateUtils.addDays(date, -1);
Calendar cal = Calendar.getInstance();
cal.setTime(a);
cal.set(Calendar.DAY_OF_WEEK, 1);
return cal.getTime();
}
代码里面有用到 lapache.common-ang包 你需要下载下 就可以使用
没有乱呀,因为缺省时每星期的第一天是星期日,所以你应该先调用
Calendar.setFirstDayOfWeek(Calendar.MONDAY);
把每星期的第一天设为星期一
那你判断一下当前日期是为周末么