/**
* 获取日期所在前周的第一天和最后一天
*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendarWeek =Calendar.getInstance();
calendarWeek.setTime(new Date());
calendarWeek.add(Calendar.WEEK_OF_MONTH, -1);
calendarWeek.setFirstDayOfWeek(Calendar.MONDAY); //以周一为首日
calendarWeek.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println("日期前周第一天:" + sdf.format(calendarWeek.getTime()));
calendarWeek.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
System.out.println("日期前周最一天:" + sdf.format(calendarWeek.getTime()));
/**
* 获取日期所在周的第一天和最后一天
*/
Calendar calendarWeek =Calendar.getInstance();
calendarWeek.setTime(new Date());
calendarWeek.add(Calendar.DATE, 0 * 7); // 0 表示当前周,-1 表示上周,1 表示下周,以此类推
calendarWeek.setFirstDayOfWeek(Calendar.MONDAY); //以周一为首日
calendarWeek.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println("日期所在周第一天:" + sdf.format(calendarWeek.getTime()));
calendarWeek.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
System.out.println("日期所在周最一天:" + sdf.format(calendarWeek.getTime()));
标签:WEEK,calendarWeek,set,sdf,获取,日期,Calendar,周日
From: https://www.cnblogs.com/codeLearn/p/17801045.html