Here you can find the source of getLastDayOfMonth()
public static String getLastDayOfMonth()
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static String getLastDayOfMonth() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar ca = Calendar.getInstance(); ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); String last = sdf.format(ca.getTime()); return last; }/*w w w .j a v a 2 s. com*/ private static int getLastDayOfMonth(int year, int month) { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { return 31; } if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } if (month == 2) { if (isLeapYear(year)) { return 29; } else { return 28; } } return 0; } private static boolean isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } }