get Last Day Of Month - Java java.util

Java examples for java.util:Month

Description

get 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 today = new Date();
        System.out.println(getLastDayOfMonth(today));
    }//from   ww w .  java2s . c o  m

    public static Date getLastDayOfMonth(Date today) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(today);

        calendar.add(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.DATE, -1);

        return calendar.getTime();
    }
}

Related Tutorials