1 public static Date getFirstDayOfWeek(Date date) { 2 Calendar c = new GregorianCalendar(); 3 c.setFirstDayOfWeek(Calendar.MONDAY); 4 c.setTime(date); 5 c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday 6 return c.getTime(); 7 } 8 9 10 public static Date getLastDayOfWeek(Date date) { 11 Calendar c = new GregorianCalendar(); 12 c.setFirstDayOfWeek(Calendar.MONDAY); 13 c.setTime(date); 14 c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday 15 return c.getTime(); 16 }
时间: 2024-10-30 10:06:23