/** * 根据第一个 * * @return 第一个胎检时间到当前时间之间的日期 */ @SuppressLint("SimpleDateFormat") private List<Date> calculatorHorizontalData(String dateStr) { String lastMus = babyDetailInfo.data.birthday; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date start = sdf.parse(lastMus); Date end = sdf.parse(dateStr); return dateSplit(start, end); } catch (Exception e) { return null; } } /** * 两个日期之间的日期 * * @param startDate 开始日期 * @param endDate 结束日期 * @return 两个日期之间的日期的所有日期 * @throws Exception 异常捕获 */ private static List<Date> dateSplit(Date startDate, Date endDate) throws Exception { Long spi = endDate.getTime() - startDate.getTime(); Long step = spi / (24 * 60 * 60 * 1000);// 相隔天数 List<Date> dateList = new ArrayList<>(); dateList.add(startDate); for (int i = 1; i <= step; i++) { dateList.add(new Date(dateList.get(i - 1).getTime() + (24 * 60 * 60 * 1000)));// 比上一天减一 } return dateList; }
java计算两个日期之间有多少天
最新推荐文章于 2024-06-29 03:11:20 发布