zoukankan      html  css  js  c++  java
  • Calendar抽象类用法一


        //日历查询
            Map finalmap = new HashMap();
         Date date = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    //获取年
    finalmap.put("year", calendar.get(Calendar.YEAR));
    //获取月
    /*Java中的月份遵循了罗马历中的规则:当时一年中的月份数量是不固定的,
    第一个月是JANUARY。而Java中Calendar.MONTH返回的数值其实是当前月距离
    第一个月有多少个月份的数值,JANUARY在Java中返回“0”,所以我们需要+1。*/
    Integer month = calendar.get(Calendar.MONTH) + 1;
    String englishMonth = "";
    if (month == 1) {
    englishMonth = "January";
    } else if (month == 2) {
    englishMonth = "February";
    } else if (month == 3) {
    englishMonth = "March";
    } else if (month == 4) {
    englishMonth = "April";
    } else if (month == 5) {
    englishMonth = "May";
    } else if (month == 6) {
    englishMonth = "June";
    } else if (month == 7) {
    englishMonth = "July";
    } else if (month == 8) {
    englishMonth = "August";
    } else if (month == 9) {
    englishMonth = "September";
    } else if (month == 10) {
    englishMonth = "October";
    } else if (month == 11) {
    englishMonth = "November";
    } else if (month == 12) {
    englishMonth = "December";
    }
    finalmap.put("month", englishMonth);
    List<RiLi> riLis = new ArrayList<RiLi>();
    Calendar cc = Calendar.getInstance();
    cc.setTime(date);
    cc.set(cc.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);//设置日期为本月1号
    /*Java中Calendar.DAY_OF_WEEK其实表示:一周中的第几天,如果周一为每周第一天,则不需要减1,若周日为每周第一天,则需要减1*/
    Integer currentDay = cc.get(Calendar.DAY_OF_WEEK) - 1;
    for (int i = 0; i < currentDay - 1; i++) {
    RiLi riLi = new RiLi();
    riLis.add(riLi);
    }
    calendar.set(Calendar.DATE, 1);//把日期设置为当月第一天
    /*roll方法只是对相应时间属性的域内做变化
    * 例如,对月份使用roll方法,它会在1-12的范围内变化,不会影响的年
    * 2011-1-15 roll(Calendar.MONTH, -1) 后是2011-12-15 */
    calendar.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
    //当月有多少天
    int maxDate = calendar.get(Calendar.DATE);
    Map map = new HashMap();
    VipUser user = vipUserService.selectVipuserByOpenId(openid);
    String phone = user.getPhone();
    map.put("phone", phone);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 1; i <= maxDate; i++) {
    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), i, 00, 00, 00);
    Date date1 = calendar.getTime();
    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), i, 23, 59, 59);
    Date date2 = calendar.getTime();
    map.put("date1", sdf.format(date1));
    map.put("date2", sdf.format(date2));
    List<String> list = publishService.selectRiLi(map);
    RiLi riLi = new RiLi();
    riLi.setDate(i);
    riLi.setRenwu(list);
    riLi.setDay(calendar.get(Calendar.DAY_OF_WEEK) - 1);
    riLis.add(riLi);
    }
    finalmap.put("riLis", riLis);
  • 相关阅读:
    题解 P3071 【[USACO13JAN]座位Seating】
    [luogu]P3398 仓鼠找sugar
    快速输入输出
    Luogu P3939 数颜色
    HEOI2016/TJOI2016 排序
    POI2011 DYN-Dynamite
    USACO17JAN Promotion Counting
    AHOI2008 聚会
    Luogu P4907 A换B problem
    网络流24题 骑士共存问题
  • 原文地址:https://www.cnblogs.com/zhangyong0908/p/9626003.html
Copyright © 2011-2022 走看看