Java Day in Month maxDayOfMonth(int year, int month)

Here you can find the source of maxDayOfMonth(int year, int month)

Description

max Day Of Month

License

Open Source License

Declaration

public static int maxDayOfMonth(int year, int month) 

Method Source Code

//package com.java2s;

public class Main {

    public static int maxDayOfMonth(int year, int month) {
        if (month <= 0 || month > 12) {
            return -1;
        }//from  ww w .  java  2s.co  m
        int day = 0;
        switch (month) {
        case 2:
            day = 28;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            day = 30;
            break;
        default:
            day = 31;
        }
        if (month == 2 && isLeapYear(year)) {
            day++;
        }
        return day;
    }

    public static boolean isLeapYear(int year) {
        return (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
    }
}

Related

  1. getStartMonthDayOfDate(String yyyyMM)
  2. is31DaysMonth(int month)
  3. isDayMonth(String types)
  4. isDayOfMonth(int num)
  5. isLastDayOfMonth(int day, int month, int year)
  6. monthDays(int y, int m)
  7. numDaysInMonth(int month)
  8. padMonthOrDay(String mod)
  9. toMonthFirstDay(String month)