Here you can find the source of numDaysToEndOfMonth()
public static int numDaysToEndOfMonth()
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int numDaysToEndOfMonth() { return maxMonthDate(new Date()) - dayNumber(new Date()); }//from w ww . ja va 2 s . com public static int maxMonthDate(Date date) { Calendar calendar = calendarDate(date); return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); } public static int dayNumber(Date date) { Calendar calender = calendarDate(date); return calender.get(Calendar.DAY_OF_MONTH); } public static Calendar calendarDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } }