Java Calendar Month getDaysInMonth(Calendar cal)

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

Description

get Days In Month

License

Open Source License

Declaration

public static int getDaysInMonth(Calendar cal) 

Method Source Code

//package com.java2s;
/**//from  w  w w .  j  a  v  a2  s. c  o  m
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import java.util.Calendar;

public class Main {
    public static int getDaysInMonth(Calendar cal) {
        return getDaysInMonth(cal.get(Calendar.MONTH), cal.get(Calendar.YEAR));
    }

    public static int getDaysInMonth(int month, int year) {
        month++;

        if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10)
                || (month == 12)) {

            return 31;
        } else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {

            return 30;
        } else {
            if (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0)) {

                return 29;
            } else {
                return 28;
            }
        }
    }
}

Related

  1. convertRemoveAfterMonth(Calendar cal)
  2. endOfMonth(Calendar calendar)
  3. floorDayOfMonth(Calendar cal)
  4. getCalDayofMonth(Date calendarDay)
  5. getDayOfMonthPostfix(Calendar cal)
  6. getFirstDateOfMonth(Calendar calendar)
  7. getFirstDayOfMonth(Calendar c)
  8. getFirstDayOfMonth(Calendar cal)
  9. getFirstDayOfMonth(final Calendar calendar, final Date date)