Get the last day of a month in Java
Description
The following code shows how to get the last day of a month.
Example
//ww w . j a va 2 s . c om
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int lastDate = calendar.getActualMaximum(Calendar.DATE);
calendar.set(Calendar.DATE, lastDate);
int lastDay = calendar.get(Calendar.DAY_OF_WEEK);
System.out.println("Last Date: " + calendar.getTime());
System.out.println("Last Day : " + lastDay);
}
}
The code above generates the following result.