因为工作上遇到要做近8周数据报表的需求,在这里记录一下这个小方法,参数是今年的周数,返回值是这周的具体日期范围:
public String getWeekDays(Integer week){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
Calendar cal=Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy");
Date date = new Date();
String year = sdf1.format(date);
cal.set(Calendar.YEAR, Integer.valueOf(year));
cal.set(Calendar.WEEK_OF_YEAR, week);
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
String beginDate = sdf.format(cal.getTime());
cal.add(Calendar.DAY_OF_WEEK, 7);
String endDate = sdf.format(cal.getTime());
return beginDate+"~"+endDate;
}
希望能帮到大家,嘻嘻