Menu
Topics Index
...
`

Gregorian Calendar Methods127 - Java Example Program


Gregorian Calendar Methods127
import java.util.*;

class GregorianCalendarMethodsTest2
{
    public static void main(String arg[])
    {
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        System.out.println("The current date : " + gc.getTime());
        
        int max = gc.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Actual Maximum : " + max);
        
        int min = gc.getActualMinimum(Calendar.DAY_OF_MONTH);
        System.out.println("Actual Minimum : " + min);
        
        min = gc.getGreatestMinimum(Calendar.DAY_OF_MONTH);
        System.out.println("Greatest Minimum : " + min);
        
        max = gc.getLeastMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Least Maximum : " + max);
        
        max = gc.getMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Maximum : " + max);
        
        min = gc.getMinimum(Calendar.DAY_OF_MONTH);
        System.out.println("Minimum : " + min);
        
        System.out.println("Time Zone : " + gc.getTimeZone().getDisplayName());
        
        System.out.println("The hash code : " + gc.hashCode());
        
        System.out.println("Get Gregorian change date : " + gc.getGregorianChange());
        
        gc.setGregorianChange(new Date(2016, 7, 10, 05, 48, 32));
        System.out.println("Gregorian Changed Date : " + gc.getGregorianChange());    
    }
}
OUTPUT

The current date : Sun Jan 19 13:11:52 IST 2014
Actual Maximum : 31
Actual Minimum : 1
Greatest Minimum : 1
Least Maximum : 28
Maximum : 31
Minimum : 1
Time Zone : India Standard Time
The hash code : -1527345468
Get Gregorian change : Fri Oct 15 05:30:00 IST 1582
Gregorian Change Date : Thu Aug 10 05:48:32 IST 3916

DESCRIPTION

In this program, the getInstance method takes the current date in gc object and getting the actual maximum, actual minimum, greatest minimum, least maximum, maximum, minimum day of month. We are also displaying time zone, hash code, getting gregorian change date and set gregorian change date.

THINGS TO TRY
  • In getActualMaximum, replace DAY_OF_MONTH by MONTH and see the output difference.
  • In getMaximum, replace DAY_OF_MONTH by DAY_OF_YEAR and see the output difference.
  • In setGregorianChange, give your own date and time and see the output.

© meritcampus 2019

All Rights Reserved.

Open In App