set End Of Month - Java java.util

Java examples for java.util:Month

Description

set End Of Month

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar calendar = Calendar.getInstance();
        System.out.println(setEndOfMonth(calendar));
    }//  w  w w . j  av  a2 s.c  o m

    public static Calendar setEndOfMonth(Calendar calendar) {
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        calendar = setEndOfDate(calendar);
        return calendar;
    }

    public static Calendar setEndOfDate(Calendar calendar) {
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar;
    }
}

Related Tutorials