zoukankan      html  css  js  c++  java
  • 获取两日期之前集合并转为String类型的集合

     1 /**
     2      * 获取两个日期之间的日期
     3      *
     4      * @param start 开始日期
     5      * @param end   结束日期
     6      * @return 日期集合
     7      */
     8     private static List<Date> getBetweenDates(Date start, Date end) {
     9         List<Date> result = new ArrayList<>();
    10         result.add(start);
    11         Calendar tempStart = Calendar.getInstance();
    12         tempStart.setTime(start);
    13         tempStart.add(Calendar.DAY_OF_YEAR, 1);
    14 
    15         Calendar tempEnd = Calendar.getInstance();
    16         tempEnd.setTime(end);
    17         while (tempStart.before(tempEnd)) {
    18             result.add(tempStart.getTime());
    19             tempStart.add(Calendar.DAY_OF_YEAR, 1);
    20         }
    21         if (start.getTime() != end.getTime()) {
    22             result.add(end);
    23         }
    24         return result;
    25     }

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

    List<String> strDateList = dateList.stream().map(simpleDateFormat::format).collect(Collectors.toList()); 

  • 相关阅读:
    单例模式
    collections额外数据类型
    logging的简单使用
    杂记
    字符编码
    面向对象编程简介
    logging模块
    re与subprocess模块
    oepnpyxl模块 与excle交互
    json序列化模块
  • 原文地址:https://www.cnblogs.com/wang-yaz/p/10862920.html
Copyright © 2011-2022 走看看