Calendar抽象类用法二
1:先查询外层-周
Map finalmap = new HashMap();
Integer recourdCount = page * 12;//page为当前页数
VipUser user = vipUserService.selectVipuserByOpenId(openid);
Date createtime = user.getCreatetime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
Calendar calendar = Calendar.getInstance();
Date date = new Date();
calendar.setTime(date);
Map map = new HashMap();
List<Week> listweek = new ArrayList<Week>();
for (int i = 0; i < recourdCount; i++) {
//判断当前日期是否先于会员创建日期
int weekno = calendar.get(Calendar.DAY_OF_WEEK) - 1;//计算今天是星期几
int day = calendar.get(Calendar.DAY_OF_MONTH);//计算今天是几号
calendar.add(Calendar.DATE, 1 - weekno - 1);
Date date1 = calendar.getTime();//每周第一天时间
calendar.add(Calendar.DATE, 6);
Date date2 = calendar.getTime();//每周最后一天时间
Integer week = calendar.get(Calendar.WEEK_OF_YEAR);//当前年份的多少周
Week wk = new Week();
wk.setDate1(sdf.format(date1));
wk.setDate2(sdf.format(date2));
wk.setWeek(week);
wk.setYear(calendar.get(Calendar.YEAR));
listweek.add(wk);
calendar.add(Calendar.DATE, -7);
Date time = calendar.getTime();
if (time.getTime() >= createtime.getTime()) {
finalmap.put("pageover", "true");
} else {
finalmap.put("pageover", "false");
break;
}
finalmap.put("listweek", listweek);
2:再查询内层:根据时间查询数据
此处代码不予贴出,只是一个条件查询语句而已