码上敲享录 > java入门知识分享 > java获取两个日期之间的所有日期

java获取两个日期之间的所有日期

上一章章节目录下一章 2018-12-26已有1347人阅读 评论(0)

java获取两个日期之间的所有日期


解决方法:

1.核心方法

private List<String> getBetweenDates(String start, String end) {

List<String> result = new ArrayList<String>();

try {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    Date start_date = sdf.parse(start);

    Date end_date = sdf.parse(end);

   Calendar tempStart = Calendar.getInstance();

   tempStart.setTime(start_date);

   Calendar tempEnd = Calendar.getInstance();

   tempEnd.setTime(end_date);

   while (tempStart.before(tempEnd)||tempStart.equals(tempEnd)) {

       result.add(sdf.format(tempStart.getTime()));

       tempStart.add(Calendar.DAY_OF_YEAR, 1);

   }

} catch (ParseException e) {

e.printStackTrace();

}

Collections.reverse(result);

   return result;

}


2.使用方法

getBetweenDates("2018-12-26","2018-01-02")


本文链接:http://www.yayihouse.com/yayishuwu/chapter/1754
向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交