Here you can find the source of getNumDaysInMonth(GregorianCalendar aCalendar)
Parameter | Description |
---|---|
aCalendar | a GregorianCalendar to query |
public static int getNumDaysInMonth(GregorianCalendar aCalendar)
//package com.java2s; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { private static final int[] mDaysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };/*w w w . j a va 2s. c o m*/ /** * Gets the number of days in the current month. * * @param aCalendar a GregorianCalendar to query * * @return the number of days in the current month taking leap years into * consideration. */ public static int getNumDaysInMonth(GregorianCalendar aCalendar) { // Figure out how many days in month. Calendar has no good way of // doing this. So we build our own and use Calendar to check leap years. int month = aCalendar.get(Calendar.MONTH); int monthDays = mDaysInMonth[month]; if (month == Calendar.FEBRUARY && aCalendar.isLeapYear(aCalendar.get(Calendar.YEAR))) { ++monthDays; } return monthDays; } }