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

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

Description

get Days In Month

License

Open Source License

Declaration

public static int getDaysInMonth(int month, int year) 

Method Source Code

//package com.java2s;
/*//from   w w w  .ja  va2  s .  c  o m
 * Copyright (C) 2007-2010 Castafiore
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see<http://www.gnu.org/licenses/>.
 */

public class Main {
    public static int getDaysInMonth(int month, int year) {
        if (month == 0) {
            return 31;
        } else if (month == 1) {
            if (isLeapYear(year)) {
                return 29;
            } else {
                return 28;
            }
        } else if (month == 2) {
            return 31;
        } else if (month == 3) {
            return 30;
        } else if (month == 4) {
            return 31;
        } else if (month == 5) {
            return 30;
        } else if (month == 6) {
            return 31;
        } else if (month == 7) {
            return 31;
        } else if (month == 8) {
            return 30;
        } else if (month == 9) {
            return 31;
        } else if (month == 10) {
            return 30;
        } else if (month == 11) {
            return 31;
        }
        return -1;
    }

    public static boolean isLeapYear(int year) {
        return (year % 4 == 0);
    }
}

Related

  1. GetDayOfMonth(String aDatetime)
  2. getDayOfMonth(String dateKey)
  3. getDayOfMonthSuffix(final int day)
  4. getDayOrMonth(int value)
  5. getDaysByMonth(int month)
  6. getDaysInMonth(int month, int year)
  7. getDaysInMonth(int monthNum)
  8. getDaysInMonth(int year, int month)
  9. getDaysInMonths()