Java Day of Month getLastDayOfMonth(int year, int month)

Here you can find the source of getLastDayOfMonth(int year, int month)

Description

Return last day of date with specified year and month

License

Open Source License

Parameter

Parameter Description
year specified year
month specified month

Return

last day value of year of current date

Declaration

public static Date getLastDayOfMonth(int year, int month) 

Method Source Code


//package com.java2s;
/*/*from w w w .  ja v  a 2s . c om*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

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

public class Main {
    /**
     * Return last day of date with specified year and month
     *
     * @param year  specified year
     * @param month specified month
     * @return last day value of year of current date
     */
    public static Date getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        int lastDay = cal.getActualMaximum(Calendar.DATE);
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        return cal.getTime();
    }
}

Related

  1. getLastDayOfMonth(final Date date)
  2. getLastdayOfMonth(int month, int year)
  3. getLastDayOfMonth(int year, int month)
  4. getLastDayOfMonth(int year, int month)
  5. getLastDayOfMonth(int year, int month)
  6. getLastDayOfMonth(int year, int month)
  7. getLastDayOfMonth(int year, int month)
  8. getLastDayOfMonth(int year, int month)
  9. getLastDayOfMonth(int year, int month)