days In Gregorian Month - Android java.util

Android examples for java.util:Month

Description

days In Gregorian Month

Demo Code


//package com.java2s;

public class Main {
    private static char[] daysInGregorianMonth = { 31, 28, 31, 30, 31, 30,
            31, 31, 30, 31, 30, 31 };/*from  www  . j  ava 2s.  co  m*/

    public static int daysInGregorianMonth(int y, int m) {
        int d = daysInGregorianMonth[m - 1];
        if (m == 2 && isGregorianLeapYear(y))
            d++; 
        return d;
    }

    public static boolean isGregorianLeapYear(int year) {
        boolean isLeap = false;
        if (year % 4 == 0)
            isLeap = true;
        if (year % 100 == 0)
            isLeap = false;
        if (year % 400 == 0)
            isLeap = true;
        return isLeap;
    }
}

Related Tutorials