package net.javaiq.examples.date;
import java.util.GregorianCalendar;
@author
public class MonthEndDateCalculator {
public static java.sql.Date calculateMonthEndDate(int month, int year) {
int[] daysInAMonth = { 29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int day = daysInAMonth[month];
boolean isLeapYear = new GregorianCalendar().isLeapYear(year);
if (isLeapYear && month == 2) {
day++;
}
GregorianCalendar gc = new GregorianCalendar(year, month - 1, day);
java.sql.Date monthEndDate = new java.sql.Date(gc.getTime().getTime());
return monthEndDate;
}
@param
public static void main(String[] args) {
int month = 2;
int year = 2076;
final java.sql.Date calculatedDate = calculateMonthEndDate(month, year);
System.out.println("Calculated month end date : " + calculatedDate);
}
}