• 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);
  • 相关阅读:
    BP神经网络的数学原理及其算法实现
    机器学习必知的10大算法
    支持向量机通俗导论(理解SVM的三层境界)
    svm算法 最通俗易懂讲解
    read/write/fsync与fread/fwrite/fflush的关系和区别
    ubuntu16.04编译QT5.6所依赖的库
    Linux下的tar压缩解压缩命令详解
    Ubuntu16下编译linux内核,报"mkimage" command not found错的解决
    Git之(一)Git是什么[转]
    mac上完整卸载删除:android studio方案
  • 原文地址:https://www.cnblogs.com/zhangyong0908/p/9626003.html
Copyright © 2020-2023  润新知