Here you can find the source of getLastDayInMonth(int month, int year)
Parameter | Description |
---|---|
month | a parameter |
year | a parameter |
public static int getLastDayInMonth(int month, int year)
//package com.java2s; /*//from ww w . ja v a 2s . c om * Copyright 2013 Georges Stephan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * * @param month * @param year * @return The number of days in the given month */ public static int getLastDayInMonth(int month, int year) { int NumberOfDays = 0; switch (month) { case 0:// January NumberOfDays = 31; break; case 1:// February if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) { NumberOfDays = 29; } else { NumberOfDays = 28; } break; case 2:// March NumberOfDays = 31; break; case 3:// April NumberOfDays = 30; break; case 4:// May NumberOfDays = 31; break; case 5:// June NumberOfDays = 30; break; case 6:// July NumberOfDays = 31; break; case 7:// August NumberOfDays = 31; break; case 8:// September NumberOfDays = 30; break; case 9:// October NumberOfDays = 31; break; case 10:// November NumberOfDays = 30; break; case 11:// December NumberOfDays = 31; break; } return (NumberOfDays); } }