Here you can find the source of getCurrentMonthLastDay()
public static String getCurrentMonthLastDay()
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; public class Main { /**//from w w w .j a v a 2 s. c om * yyyy-MM-dd Comment for <code>onlyDateFmt</code> */ public static final SimpleDateFormat onlyDateFmt = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); private static int monthDays[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public static String getCurrentMonthLastDay() { String current = getCurrentStringDate(); int year = Integer.parseInt(current.substring(0, 4)); int month = Integer.parseInt(current.substring(5, 7)); int day = getMonthDaysByYearMonth(year, month); return current.substring(0, 7) + "-" + day; } public static String getCurrentStringDate() { return onlyDateFmt.format(getCurrentDate()); } public static int getMonthDaysByYearMonth(int year, int month) { if (month == 2) { GregorianCalendar gc = new GregorianCalendar(); if (gc.isLeapYear(year)) return monthDays[month - 1] + 1; else return monthDays[month - 1]; } else return monthDays[month - 1]; } public static Date getCurrentDate() { return new Date(System.currentTimeMillis()); } }