Android Day in Month Get perMonthDays(Calendar cal)

Here you can find the source of perMonthDays(Calendar cal)

Description

per Month Days

Declaration

public static int perMonthDays(Calendar cal) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static int perMonthDays(Calendar cal) {
        int maxDays = 0;
        int month = cal.get(Calendar.MONTH);
        switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            maxDays = 31;/*w  ww  .java2s  .  com*/
            break;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            maxDays = 30;
            break;
        case Calendar.FEBRUARY:
            if (isLeap(cal.get(Calendar.YEAR))) {
                maxDays = 29;
            } else {
                maxDays = 28;
            }
            break;
        }
        return maxDays;
    }

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

Related

  1. daysInMonth(int day, int month, int year)
  2. getDaysInMonth(int month, int year)
  3. getNextMonthDays(String argDate)
  4. daysInMonth(Calendar c)
  5. getNextMonthDays(String argDate)
  6. numDaysToEndOfMonth()
  7. dayNumber(Date date)
  8. getDayOfWeek(long time)
  9. getStringDayOfMonth(Date date)