get Last Day Of Month and return java.util.Date - Android java.util

Android examples for java.util:Day

Description

get Last Day Of Month and return java.util.Date

Demo Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main{

    public static Date getLastDayOfMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);//from   w w w.  jav a 2  s. co m

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        return new GregorianCalendar(year, month, maxDay, 23, 59, 59)
                .getTime();
    }

}

Related Tutorials