/** * 獲取兩個日期之間的全部月(字符串格式, 按月計算) * * @param start * @param end * @return */ public static List<String> getBetweenMonths(Date start, Date end) { List<String> result = new ArrayList<String>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Calendar tempStart = Calendar.getInstance(); tempStart.setTime(start); // 加了一個月 tempStart.add(Calendar.MONTH, 1); Calendar tempEnd = Calendar.getInstance(); tempEnd.setTime(end); result.add(sdf.format(start)); while (tempStart.before(tempEnd)) { result.add(sdf.format(tempStart.getTime())); tempStart.add(Calendar.MONTH, 1); } return result; }