Java Day in Month daysInMonth(int year, int month)

Here you can find the source of daysInMonth(int year, int month)

Description

days In Month

License

Apache License

Declaration

private static int daysInMonth(int year, int month) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static int daysInMonth(int year, int month) {
        int daysInMonth;
        switch (month) {
        case 1://from   w w  w  . ja  va  2s. c  o  m
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            daysInMonth = 31;
            break;
        case 2:
            if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
                daysInMonth = 29;
            } else {
                daysInMonth = 28;
            }
            break;
        default:
            // returns 30 even for nonexistant months 
            daysInMonth = 30;
        }
        return daysInMonth;
    }
}

Related

  1. currentMonthFirstDay()
  2. dayForMonth(String pTime)
  3. daysInMonth(int month, boolean isLeapYear)
  4. daysInMonth(int month, int year)
  5. daysOfMonth(int year)
  6. daysOfMonth(int year, int month)
  7. firstDayOfLastMonth()
  8. firstDayOfMonth(int commonMonthIndx, int iyear)