/** * 获取上周周几的日期,默认一周从周一开始 * @param dayOfWeek * @param weekOffset * @return */ public static Date getDayOfWeek(int dayOfWeek,int weekOffset){ return getDayOfWeek(Calendar.MONDAY,dayOfWeek,weekOffset); } /** * 获取上(下)周周几的日期 * @param firstDayOfWeek { @link Calendar} * 值范围SUNDAY
, *MONDAY
,TUESDAY
,WEDNESDAY
, *THURSDAY
,FRIDAY
, andSATURDAY
* @param dayOfWeek { @link Calendar} * @param weekOffset 周偏移,上周为-1,本周为0,下周为1,以此类推 * @return */ public static Date getDayOfWeek(int firstDayOfWeek,int dayOfWeek,int weekOffset){ if(dayOfWeek>Calendar.SATURDAY || dayOfWeekCalendar.SATURDAY || firstDayOfWeek < Calendar.SUNDAY){ return null; } Calendar date=Calendar.getInstance(Locale.CHINA); date.setFirstDayOfWeek(firstDayOfWeek); //周数减一,即上周 date.add(Calendar.WEEK_OF_MONTH,weekOffset); //日子设为周几 date.set(Calendar.DAY_OF_WEEK, dayOfWeek); //时分秒全部置0 date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); return date.getTime(); }