Get the last day of a month
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.text.DateFormat;
public class DateUtils {
public static String getLastDay(String year, String month) {
GregorianCalendar calendar = new GregorianCalendar();
int yearInt = Integer.parseInt(year);
int monthInt = Integer.parseInt(month);
monthInt = monthInt - 1;
calendar.set(yearInt, monthInt, 1);
int dayInt = calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
return Integer.toString(dayInt);
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Get:
- Day of Week
- Number of days in a month
- Month of year
- Current month name
- Full date time
- Get all attributes from a Calendar
- Get year, month, day, minute, hour, second, milli second from java.util.Date through Calendar
- Get age from a birthday date
- Get Monday
- Get next Sunday
- Get today's date
- Get the last day of a month
- Get date of yesterday
- Get Day-of-Week for a Particular Date
- Get date of last week
- Get date of last month
- Get last Date of This Month
- Get Month in a leap year
- Get start of a month
- Get the end of a month
- Get noon of a day
- Get days since a date
- Get TimeZone
- Get Last day fo previous Month
- Is an hour between an interval
- Is a Year a Leap Year