Java Year Month getDaysOfMonth(String year, String month)

Here you can find the source of getDaysOfMonth(String year, String month)

Description

get Days Of Month

License

Apache License

Declaration

public static int getDaysOfMonth(String year, String month) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static int getDaysOfMonth(String year, String month) {
        int days = 0;
        if (month.equals("1") || month.equals("3") || month.equals("5") || month.equals("7") || month.equals("8")
                || month.equals("10") || month.equals("12")) {
            days = 31;//  w w  w . j  a va2s.  c  om
        } else if (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11")) {
            days = 30;
        } else {
            if ((Integer.parseInt(year) % 4 == 0 && Integer.parseInt(year) % 100 != 0)
                    || Integer.parseInt(year) % 400 == 0) {
                days = 29;
            } else {
                days = 28;
            }
        }

        return days;
    }

    public static int getDaysOfMonth(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, 1);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }
}

Related

  1. getBeginEndDayOfMonth(String yearMonthString)
  2. getCurrentYearMonthDay()
  3. getCurYearMonth()
  4. getDate(int year, int month, int day)
  5. getDate(int year, int month, int day, int hour, int minute)
  6. getEndDateOfMonth(int year, int month)
  7. getFirstDay(String yearMonthStr, int range)
  8. getFirstDayByMonthWeek(int year, int month, int week)
  9. getFirstDayOfMonth(int year, int month)