Java Month getAllowMonth(String startdate, int count)

Here you can find the source of getAllowMonth(String startdate, int count)

Description

get Allow Month

License

Apache License

Declaration

public static String getAllowMonth(String startdate, int count) 

Method Source Code

//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;
    }
}

Related

  1. doy2month(int year, int doy)
  2. extractMonthFromDate(String dateString)
  3. findMonth(String strMonth)
  4. fixMonth(int month)
  5. fixMonth(String m)
  6. getAssignMonth(String date)
  7. getCurrDateByMonth(String date)
  8. getEnligthMonth(String en)
  9. getEnMonth(String month)