Here you can find the source of getMaxDayByYearMonth(String ym)
public static int getMaxDayByYearMonth(String ym)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static int getMaxDayByYearMonth(String ym) { int day = 0; try {/*from w ww . j a v a2 s .c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Calendar calendar = new GregorianCalendar(); Date date = sdf.parse(ym); calendar.setTime(date); day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); } catch (ParseException e) { day = 0; } return day; } }