Code example for GregorianCalendar

Methods: beforegetisLeapYear

//        checkShortParse("2004-8-1 +26 weeks",now,target); 
    // Test leap year if current year is a leap year 
    public void testFeb29IfLeapYear() throws Exception{ 
        GregorianCalendar now = new GregorianCalendar();
        final int thisYear = now.get(Calendar.YEAR);
        if (now.isLeapYear(thisYear) && now.before(new GregorianCalendar(thisYear,Calendar.AUGUST,29))){
            GregorianCalendar target = new GregorianCalendar(thisYear,Calendar.FEBRUARY,29);
            checkShortParse("Feb 29th",now,target);
        } else { 
            System.out.println("Skipping Feb 29 test");
    // Test Feb 29 for a known leap year 
    public void testFeb29LeapYear() throws Exception{ 
        int year = 2000; // Use same year for current and short date
        GregorianCalendar now = new GregorianCalendar(year, Calendar.APRIL, 1, 12, 0);
        checkShortParse("Feb 29th 2000",now,new GregorianCalendar(year, Calendar.FEBRUARY,29));
Stop searching for code, let great code find you!  Add Codota to your java IDE