Java Day in Month isLastDayOfMonth(int day, int month, int year)

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

Description

Verify if the given date is the last day in the month.

License

Open Source License

Parameter

Parameter Description
day Day.
month Month.
year Year.

Return

Last day or not.

Declaration

public static final boolean isLastDayOfMonth(int day, int month, int year) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w ww  .j  a v  a2 s  .  com*/
     * <p>
     * Verify if the given date is the last day in the month.
     * </p>
     * @param day Day.
     * @param month Month.
     * @param year Year.
     * @return Last day or not.
     */
    public static final boolean isLastDayOfMonth(int day, int month, int year) {
        if (month == 1) { // february
            return isLeapYear(year) ? day == 29 : day == 28;
        } else {
            return is31DaysMonth(month) ? day == 31 : day == 30;
        }
    }

    /**
     * <p>
     * Verify if a given year is leap.
     * </p>
     * @param year Year.
     * @return Leap or not.
     */
    public static final boolean isLeapYear(int year) {
        if (year % 4 == 0) {
            return year % 100 != 0 ? true : year % 400 == 0;
        }
        //
        return false;
    }

    /**
     * <p>
     * Verify if a given month has 31 days or not.
     * </p>
     * @param month Month.
     * @return Has 31 days or not.
     */
    public static final boolean is31DaysMonth(int month) {
        int[] months31 = { 0, 2, 4, 6, 7, 9, 11 };
        //
        for (int i = months31.length - 1; i >= 0; i--) {
            if (months31[i] == month) {
                return true;
            }
        }
        //
        return false;
    }
}

Related

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