The document discusses the Calendar and GregorianCalendar classes in Java. It provides details on their constructors, methods, and usage. Calendar is an abstract class that provides methods for converting between a date and calendar fields like year, month, etc. GregorianCalendar is a concrete subclass that implements the standard Gregorian calendar system. It supports both the Julian and Gregorian systems and handles leap years according to Gregorian rules. Examples are provided to demonstrate using these classes.
3. Calendar
● The java.util.calendar class is an abstract class that
provides methods for converting between a specific
instant in time and a set of calendar fields such as
YEAR, MONTH, DAY_OF_MONTH, HOUR, and so
on
● This class also provides additional fields and
methods for implementing a concrete calendar
system outside the package.
● Calendar defines the range of values returned by
certain calendar fields.
4. Constructors in calendar
Constructors Description
Protected Calendar() This constructor constructs a calendar
with the default time zone and locale.
Protected Calendar(TimeZone
zone,Locale aLocale)
This constructor constructs a calendar
with the specified time zone and locate.
5. Methods in Calendar class
Methods Description
Abstract void add(int field, int amount) This method adds or subracts the
specified amoutn of time to the given
calendar on the calendar's rules
Boolean after(object when) This method returns whether this
calendar represents a time after the time
represented by the specified obejct
Boolean before(object when) This method returns whether this
calendar represents a time before the
time represented by the specified
obejct
Int compareTo(Calendar
anotherCalendar)
This method compares the time values
represented by two calendar objects
Int get(int field) This method returns the value of the
given calendar field
Static Calendar getInstance() This method gets a calendar using the
default time zone and locale.
8. Gregorian Calendar
● The java.util.GregorianCalendar class is a concrete
subclass of Calendar and provides the standard calendar
system used by most of the world.
● It is a hybrid calendar that supports both the Julian and
Gregorian calendar systems with the support of a single
discontinuity, which corresponds by default to the
Gregorian date when the Gregorian calendar was
instituted.
● The Julian calendar specifies leap years every four years,
whereas the Gregorian calendar omits century years
which are not divisible by 400.
9. Constructors in GregorianCalendar
Constructor Description
GregorianCalendar() This constructs a default
GregorianCalendar using the current time
in the default timezone and default locale
GregorianCalendar(int year, int month, int
dayOfMonth)
This constructs a GregorianCalendar with
the given date set in the default time and
with default locale
10. Methods in GregorianCalendar
Methods Description
Abstract void add(int field, int amount) This method adds or subracts the
specified amoutn of time to the given
calendar on the calendar's rules
Protected void computeTime() This mehtod converrts calendar field
values to the time value
Boolean equals(Object obj) This method compares this
GregorianCaendar to the specified
Obejct.
Date getGregorianChange() This method gets the Gregorian Calendar
change date.
Int getGregorianChange() This method gets the Gregorian Calendar
change date
TimeZone getTimeZone() This method gets the time zone.
Boolean isLeapYear(int year) This method determines if the given year
is a leap year.