zoukankan      html  css  js  c++  java
  • java中获取两个时间中的每一天

    引入下面方法即可:

    /**
         * 获取两个时间中的每一天
         * @param bigtimeStr 开始时间 yyyy-MM-dd
         * @param endTimeStr 结束时间 yyyy-MM-dd
         * @return
         * @throws ParseException
         */
        private List<String> getDays(String bigtimeStr, String endTimeStr) throws ParseException {
            Date bigtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(bigtimeStr + " 00:00:00");
            Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endTimeStr + " 00:00:00");
            //定义一个接受时间的集合
            List<Date> lDate = new ArrayList<>();
            lDate.add(bigtime);
            Calendar calBegin = Calendar.getInstance();
            // 使用给定的 Date 设置此 Calendar 的时间
            calBegin.setTime(bigtime);
            Calendar calEnd = Calendar.getInstance();
            // 使用给定的 Date 设置此 Calendar 的时间
            calEnd.setTime(endtime);
            // 测试此日期是否在指定日期之后
            while (endtime.after(calBegin.getTime()))  {
                // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
                calBegin.add(Calendar.DAY_OF_MONTH, 1);
                lDate.add(calBegin.getTime());
            }
            List<String> datas = new LinkedList<>();
            for (Date date : lDate) {
                datas.add(new SimpleDateFormat("yyyy/MM/dd").format(date));
            }
            return datas;
        }
  • 相关阅读:
    使用 PyCharm 远程调试 Django 项目
    (坑集)Python环境配置
    字典的使用
    列表的使用
    字符串的魔法
    php 文件函数
    php 时间函数
    php xajax库基本知识
    php header函数
    c++注释
  • 原文地址:https://www.cnblogs.com/007sx/p/9953211.html
Copyright © 2011-2022 走看看