Here you can find the source of getLastDayOfMonth(int year, int month)
Parameter | Description |
---|---|
year | a parameter |
month | a parameter |
public static String getLastDayOfMonth(int year, int month)
//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); } }