Here you can find the source of getDaysInMonth(int month, int year)
public static int getDaysInMonth(int month, int year)
//package com.java2s; /*//from w w w .ja va2 s . c o m * Copyright (C) 2007-2010 Castafiore * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see<http://www.gnu.org/licenses/>. */ public class Main { public static int getDaysInMonth(int month, int year) { if (month == 0) { return 31; } else if (month == 1) { if (isLeapYear(year)) { return 29; } else { return 28; } } else if (month == 2) { return 31; } else if (month == 3) { return 30; } else if (month == 4) { return 31; } else if (month == 5) { return 30; } else if (month == 6) { return 31; } else if (month == 7) { return 31; } else if (month == 8) { return 30; } else if (month == 9) { return 31; } else if (month == 10) { return 30; } else if (month == 11) { return 31; } return -1; } public static boolean isLeapYear(int year) { return (year % 4 == 0); } }