public static Date getDayOfWeek(int dayOfWeek,int weekOffset){ if(dayOfWeek>Calendar.SATURDAY || dayOfWeek<Calendar.SUNDAY){ return null; } Calendar date=Calendar.getInstance(Locale.CHINA); //将每周第一天设为星期一,默认是星期天 date.setFirstDayOfWeek(Calendar.MONDAY); //周数减一,即上周 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(); }
时间: 2024-10-20 17:41:15