Here you can find the source of getDaysOfCurMonth(final String time)
public static int getDaysOfCurMonth(final String time)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int getDaysOfCurMonth() { int curyear = Integer.valueOf(getCurrentYear()).intValue(); int curMonth = Integer.valueOf(getCurrentMonth()).intValue(); int mArray[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//w w w .j ava2 s .c o m if ((curyear % 400 == 0) || ((curyear % 100 != 0) && (curyear % 4 == 0))) { mArray[1] = 29; } return mArray[curMonth - 1]; } public static int getDaysOfCurMonth(final String time) { if (time.length() != 7) { throw new NullPointerException("yyyy-MM"); } String[] timeArray = time.split("-"); int curyear = Integer.valueOf(timeArray[0]).intValue(); int curMonth = Integer.valueOf(timeArray[1]).intValue(); if (curMonth > 12) { throw new NullPointerException("null pointer "); } int mArray[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if ((curyear % 400 == 0) || ((curyear % 100 != 0) && (curyear % 4 == 0))) { mArray[1] = 29; } if (curMonth == 12) { return mArray[0]; } return mArray[curMonth - 1]; } public static String getCurrentYear() { return getFormatCurrentTime("yyyy"); } public static String getCurrentMonth() { return getFormatCurrentTime("MM"); } public static String getFormatCurrentTime(String format) { return getFormatDateTime(new Date(), format); } public static String getFormatDateTime(Date date, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } }