Tuesday, 31 October 2017

java.util.GregorianCalendar class in java

GregorianCalendar Class

This class is a concrete implementation of a Calendar class that implements the normal Gregorian calendar with which you are familiar.

The getInstance( ) method of Calendar returns a GregorianCalendar initialized with the current date and time in the default locale and time zone.


Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.

GregorianCalendar(int year, int month, int date)
Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.


boolean isLeapYear(int year)

This is a useful method of GregorianCalendar.
Determines if the given year is a leap year.

void add(int field, int amount)
Adds the specified (signed) amount of time to the given time field, based on the calendar's rules.

protected void computeFields()

Converts UTC as milliseconds to time field values.

protected void computeTime()

Overrides Calendar Converts time field values to UTC as milliseconds.

boolean equals(Object obj)

Compares this GregorianCalendar to an object reference.

int get(int field)

Gets the value for a given time field.

int getActualMaximum(int field)

Returns the maximum value that this field could have, given the current date.

int getActualMinimum(int field)

Returns the minimum value that this field could have, given the current date.

int getGreatestMinimum(int field)

Returns the highest minimum value for the given field if varies.

Date getGregorianChange()

Gets the Gregorian Calendar change date.

int getLeastMaximum(int field)

Returns the lowest maximum value for the given field if varies.

int getMaximum(int field)

Returns maximum value for the given field.

Date getTime()

Gets this Calendar's current time.

long getTimeInMillis()

Gets this Calendar's current time as a long.

TimeZone getTimeZone()

Gets the time zone.

int getMinimum(int field)

Returns minimum value for the given field.


import java.util.*;
class Caldemo
    public static void main(String args[])
         Calendar cal=Calendar.getInstance();
         Date d=cal.getTime();
         GregorianCalendar ge=new GregorianCalendar();

Post a Comment

Click Here