Java Month getMonthLength(int year, int m)

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

Description

get Month Length

License

Open Source License

Declaration

public static int getMonthLength(int year, int m) 

Method Source Code

//package com.java2s;

public class Main {
    private static final int[] MONTH_LENGTH = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    private static final int[] LEAP_MONTH_LENGTH = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    public static int getMonthLength(int year, int m) {
        if ((m < 1) || (m > 12)) {
            return -1;
        }//from   w ww.j  av a2 s.  c  o  m
        if (isLeapYear(year)) {
            return LEAP_MONTH_LENGTH[m];
        }
        return MONTH_LENGTH[m];
    }

    public static boolean isLeapYear(int y) {
        boolean result = false;

        if (((y % 4) == 0) && // must be divisible by 4...
                ((y < 1582) || // and either before reform year...
                        ((y % 100) != 0) || // or not a century...
                        ((y % 400) == 0))) { // or a multiple of 400...
            result = true; // for leap year.
        }
        return result;
    }
}

Related

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