Java tutorial
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int getNumberOfDaysInPreviousMonth(Date someDayInCurrentMonth) { Calendar lastMonthCal = Calendar.getInstance(); lastMonthCal.setTime(someDayInCurrentMonth); lastMonthCal.add(Calendar.MONTH, -1); return lastMonthCal.getActualMaximum(Calendar.DAY_OF_MONTH); } }