Here you can find the source of isLastDayOfMonth(int day, int month, int year)
Verify if the given date is the last day in the month.
Parameter | Description |
---|---|
day | Day. |
month | Month. |
year | Year. |
public static final boolean isLastDayOfMonth(int day, int month, int year)
//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; } }