Java Month getMonthLength(final int year, final int month)

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

Description

get Month Length

License

Open Source License

Declaration

public static int getMonthLength(final int year, final int month) 

Method Source Code

//package com.java2s;

public class Main {
    private final static int[] DAYS_OF_MONTH = new int[] { 0, 31, // 1
            28, // 2
            31, // 3
            30, // 4
            31, // 5
            30, // 6
            31, // 7
            31, // 8
            30, // 9
            31, // 10
            30, // 11
            31 // 12
    };/*  ww w . j  av a2 s.c  o  m*/

    public static int getMonthLength(final int year, final int month) {
        if (month == 2 && isLeapYear(year)) {
            return 29;
        }
        return DAYS_OF_MONTH[month];
    }

    public static boolean isLeapYear(final int year) {
        return ((year % 4) == 0) // must be divisible by 4...
                && ((year < 1582) // and either before reform year...
                        || ((year % 100) != 0) // or not a century...
                        || ((year % 400) == 0)); // or a multiple of 400...
    }
}

Related

  1. getMonthEnd(String strdate)
  2. getMonthFromDate(String date)
  3. getMonthFromYM(String ym)
  4. getMonthInEnglish(int month)
  5. getMonthLastDate(int month, int year)
  6. getMonthLength(int year, int m)
  7. getMonthLength(int year, int month)
  8. getMonthMaxDate(String str)
  9. getMonthOfNextQuarter(String yearAndMonth)