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

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

Description

get the last date of given month and year

License

Apache License

Parameter

Parameter Description
year a parameter
month a parameter

Declaration

public static String getLastDayOfMonth(int year, int month) 

Method Source Code

//package com.java2s;
/**/*from w w  w.jav  a 2s.  com*/
 *  Copyright (c) 2012-2014 http://www.eryansky.com
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 */

import java.util.Calendar;

public class Main {
    /**
     * get the last date of given month and year
     *
     * @param year
     * @param month
     * @return
     */
    public static String getLastDayOfMonth(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DATE, 1);
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DAY_OF_YEAR, -1);
        return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH);
    }
}

Related

  1. getLastDayOfMonth(Date sDate)
  2. getLastDayOfMonth(final Date date)
  3. getLastdayOfMonth(int month, int year)
  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)