查询两个时间之间的 日期 /** * 获取两个日期之间的所有日期(yyyy-MM-dd) * @Description TODO * @param begin * @param end * @return * @author XuJD * @date 2017-4-1 */private static List getBetweenDates(Date begin, Dat
/** * 获取两个日期之间的所有日期(yyyy-MM-dd) * @Description TODO * @param begin * @param end * @return * @author XuJD * @date 2017-4-1 */ private static List查询两个时间之间的 月份getBetweenDates(Date begin, Date end) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List result = new ArrayList (); Calendar tempStart = Calendar.getInstance(); tempStart.setTime(begin); /* Calendar tempEnd = Calendar.getInstance(); tempStart.add(Calendar.DAY_OF_YEAR, 1); tempEnd.setTime(end); while (tempStart.before(tempEnd)) { result.add(tempStart.getTime()); tempStart.add(Calendar.DAY_OF_YEAR, 1); }*/ while(begin.getTime()<=end.getTime()){ result.add(sdf.format(tempStart.getTime())); tempStart.add(Calendar.DAY_OF_YEAR, 1); begin = tempStart.getTime(); } return result; }
private static List查询两个时间之间的小时getMonthBetween(String minDate, String maxDate) throws ParseException { ArrayList result = new ArrayList (); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月 Calendar min = Calendar.getInstance(); Calendar max = Calendar.getInstance(); min.setTime(sdf.parse(minDate)); min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1); max.setTime(sdf.parse(maxDate)); max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2); Calendar curr = min; while (curr.before(max)) { result.add(sdf.format(curr.getTime())); curr.add(Calendar.MONTH, 1); } return result; }
/** * 获取两个日期之间的有几个小时 * @Description TODO * @param begin * @param end * @return * @author XuJD * @date 2017-4-1 */ private static List查询两个时间之间的分钟getBetweenHours(Date begin, Date end) { List result = new ArrayList (); Calendar tempStart = Calendar.getInstance(); tempStart.setTime(begin); while(begin.getTime()<=end.getTime()){ result.add(sdft.format(tempStart.getTime()).substring(0,2)); tempStart.add(Calendar.HOUR_OF_DAY, 1); begin = tempStart.getTime(); } return result; }
/** * 获取两个日期之间有几分钟 * @Description TODO * @param begin * @param end * @return * @author XuJD * @date 2017-4-1 */ private static List查询两个时间之间的秒钟getBetweenMinutes(Date begin, Date end) { List result = new ArrayList (); Calendar tempStart = Calendar.getInstance(); tempStart.setTime(begin); while(begin.getTime()<=end.getTime()){ result.add(sdft.format(tempStart.getTime()).substring(0,5)); tempStart.add(Calendar.MINUTE, 1); begin = tempStart.getTime(); } return result; }
/** * 获取两个日期之间有几秒钟 * @Description TODO * @param begin * @param end * @return * @author XuJD * @date 2017-4-1 */ private static ListgetBetweenSeconds(Date begin, Date end) { List result = new ArrayList (); Calendar tempStart = Calendar.getInstance(); tempStart.setTime(begin); while(begin.getTime()<=end.getTime()){ result.add(sdft.format(tempStart.getTime())); tempStart.add(Calendar.SECOND, 1); begin = tempStart.getTime(); } return result; }