get Month End - Java java.util

Java examples for java.util:Month

Description

get Month End

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        int year = 2;
        int month = 2;
        System.out.println(getMonthEnd(year, month));
    }//from   ww w  . j  a  va2 s.  c o  m

    public static Date getMonthEnd(int year, int month) {
        //      return getMonthEndCalendar(year, month).getTime();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.DATE,
                calendar.getActualMaximum(Calendar.DATE));
        return calendar.getTime();
    }
}

Related Tutorials