last Day Of Month - Java java.util

Java examples for java.util:Month

Description

last Day Of Month

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        Date currentDate = new Date();
        System.out.println(lastDayOfMonth(currentDate));
    }/*from  www  .  j  ava2 s  .c o m*/

    @SuppressWarnings("deprecation")
    public final static Date lastDayOfMonth(Date currentDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        final int lastDay = calendar
                .getActualMaximum(Calendar.DAY_OF_MONTH);
        Date lastDate = calendar.getTime();
        lastDate.setDate(lastDay);
        return lastDate;
    }
}

Related Tutorials