赞
踩
- public static List<Map<String, Object>> getDays() {
-
- String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
-
- //创建日历类
- Calendar calendar = Calendar.getInstance();
- //获取当月月份
- int month = calendar.get(Calendar.MONTH) + 1;
- //设置当前月份
- calendar.set(0, month, 0);
- //获取当月每个月有多少天
- int monthday = calendar.get(Calendar.DAY_OF_MONTH);
- //设置当前时间
- calendar.setTime(new Date());
- //今天是几号
- int today = calendar.get(Calendar.DATE);
- //今天是周几
- String weekday = weekDays[calendar.get(Calendar.DAY_OF_WEEK)-1];
- //今天周几 对应的下标
- int index = calendar.get(Calendar.DAY_OF_WEEK)-1;
-
- List<Map<String, Object>> list = new ArrayList<>();
-
- for (int i = 0; i < 7; i++) {
-
- Map<String, Object> map = new HashMap<>();
-
- //将周几信息放入 如果index > 6 也就是说已经到周日了 就跳回周日 也就是index = 0 重新遍历
- map.put("weekday", weekDays[index = index > 6 ? 0 : index]);
- //将日期信息放入 如果today 已经大于 本月最大日期 则从1号开始
- map.put("day", today = today > monthday ? 1 : today);
- list.add(map);
- today++;
- index++;
- }
- return list;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。