Friday, January 17, 2014

Get maximum day of month of leap year

This example show how to get maximum day of month of leap year, using getActualMaximum().

Get maximum day of month of leap year
Get maximum day of month of leap year

package javacalendar_leapyear;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * @web http://java-buddy.blogspot.com/
 */
public class JavaCalendar_LeapYear {

    public static void main(String[] args) {
        Calendar cal1 = new GregorianCalendar(2014, Calendar.FEBRUARY, 1);
        int days1a = cal1.getActualMaximum(Calendar.DAY_OF_MONTH);
        int days1b = cal1.getMaximum(Calendar.DAY_OF_MONTH);

        Calendar cal2 = new GregorianCalendar(2016, Calendar.FEBRUARY, 1);
        int days2a = cal2.getActualMaximum(Calendar.DAY_OF_MONTH);
        int days2b = cal2.getMaximum(Calendar.DAY_OF_MONTH);
        
        System.out.println("2014 FEBRUARY ActualMaximum DAY_OF_MONTH: " + days1a);
        System.out.println("2014 FEBRUARY Maximum DAY_OF_MONTH: " + days1b);
        System.out.println("2016 FEBRUARY ActualMaximum DAY_OF_MONTH: " + days2a);
        System.out.println("2016 FEBRUARY Maximum DAY_OF_MONTH: " + days2b);
    }
    
}

No comments:

Post a Comment