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

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

Description

get Last Day Of Month

License

Open Source License

Declaration

public static int getLastDayOfMonth(int year, int month) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static int getLastDayOfMonth(int year, int month) {
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            return 31;
        }//from w  ww  .  j  a v a 2  s  .co  m
        if (month == 4 || month == 6 || month == 9 || month == 11) {
            return 30;
        }
        if (month == 2) {
            if (isLeapYear(year)) {
                return 29;
            } else {
                return 28;
            }
        }
        return 0;
    }

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

Related

  1. getDaysInMonths()
  2. getDaysOfMonth(Date startdate, Date enddate, String month)
  3. getFirstDayOfMonth(int year, int month)
  4. getFirstdayOfMonth(String year, String month)
  5. getLastDayInMonth(int month, int year)
  6. getLastDayOfMonth(String monthInitials)
  7. getMaxDayByMonth(String month)
  8. getMaxMonthDay(int year, int month)
  9. getMonthDay(int year, int month)