Java Month Day daysInMonth(GregorianCalendar c)

Here you can find the source of daysInMonth(GregorianCalendar c)

Description

Here get the number of days in particular month

License

Open Source License

Parameter

Parameter Description
c GregorianCalendar

Return

int Number of days in particular month

Declaration

public static int daysInMonth(GregorianCalendar c) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    /**/*  ww w  .ja v a2  s. c  o m*/
     * MONTH
     */
    public static final int MONTH = 2;
    /**
     * YEAR
     */
    public static final int YEAR = 3;

    /**
     * Here get the number of days in particular month
     *
     * @param c GregorianCalendar
     *
     * @return int Number of days in particular month
     */
    public static int daysInMonth(GregorianCalendar c) {
        int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        daysInMonths[1] += c.isLeapYear(c.get(GregorianCalendar.YEAR)) ? 1 : 0;
        return daysInMonths[c.get(GregorianCalendar.MONTH)];
    }
}

Related

  1. addMonthsAndDays(Date date, int months, int days)
  2. addMonthToDayOfMonth(Calendar c, int dayOfMonth, int monthInterval)
  3. firstDayOfMonth(Date date)
  4. firstDayOfMonth(Date date)
  5. firstMonthDay(String dateTime, int num)
  6. getActualMaximumDayOfMonth(final Date date)