Here you can find the source of getAllowMonth(String startdate, int count)
public static String getAllowMonth(String startdate, int count)
//package com.java2s; //License from project: Apache License public class Main { public static String getAllowMonth(String startdate, int count) { String tempdate = getCurMonthDayStr(startdate); for (int i = 0; i < count; i++) { tempdate = getNextMonthDayStr(tempdate); }//from ww w . j a va2 s . c o m return tempdate; } public static String getCurMonthDayStr(String curday) { int year = getYear(curday); String monthStr = getMonth(curday); int month = Integer.parseInt(monthStr); monthStr = String.valueOf(month); if (monthStr.length() == 1) monthStr = "0" + monthStr; return year + "-" + monthStr + "-01"; } public static String getNextMonthDayStr(String curday) { int year = getYear(curday); String monthStr = getMonth(curday); int month = Integer.parseInt(monthStr); if (month >= 12) { month = 1; year = year + 1; } else month = month + 1; monthStr = String.valueOf(month); if (monthStr.length() == 1) monthStr = "0" + monthStr; return year + "-" + monthStr + "-01"; } public static int getYear(String day) { if (day == null) return 0; if (day.length() < 8) return 0; return Integer.parseInt(day.substring(0, 4)); } public static String getMonth(String day) { if (day == null) return "0"; if (day.length() < 8) return "0"; int m = day.indexOf("-", 0); int n = day.lastIndexOf("-"); String temp = day.substring(m + 1, n); if (temp.length() == 1) temp = "0" + temp; return temp; } }