Menu
Topics Index
...
`

Gregorian Calendar - Java Example Program


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

class GregorianCalendarTest
{
    public static void main(String arg[])
    {
        GregorianCalendar gc = new GregorianCalendar();
        System.out.println("The current date is : " + gc.getTime());
                
        System.out.println("Month : " + gc.get(Calendar.MONTH));
        System.out.println("Date : " + gc.get(Calendar.DATE));
        System.out.println("Year : " + gc.get(Calendar.YEAR));
        
        System.out.println("Hour : " + gc.get(Calendar.HOUR));
        System.out.println("Hour of day : " + gc.get(Calendar.HOUR_OF_DAY));
        System.out.println("Minute : " + gc.get(Calendar.MINUTE));
        System.out.println("Second : " + gc.get(Calendar.SECOND));
        System.out.println("Milli second : " + gc.get(Calendar.MILLISECOND));
        
        System.out.println("Day of month : " + gc.get(Calendar.DAY_OF_MONTH));
        System.out.println("Day of week : " + gc.get(Calendar.DAY_OF_WEEK));
        System.out.println("Week of year : " + gc.get(Calendar.WEEK_OF_YEAR));
        System.out.println("Week of month : " + gc.get(Calendar.WEEK_OF_MONTH));    
    }
}
OUTPUT

The current date is : Sun Jan 19 12:24:02 IST 2014
Month : 0
Date : 19
Year : 2014
Hour : 0
Hour of day : 12
Minute : 24
Second : 2
Milli second : 295
Day of month : 19
Day of week : 1
Week of year : 4
Week of month : 4

DESCRIPTION

In this program, we are creating a date using GregorianCalendar and extracting individual month, date, year, hour, hour of the day, minute, second, milli second, day of month, day of week, week of year and week of month. Note the output will be different when you run this program.

© meritcampus 2019

All Rights Reserved.

Open In App