calendar class in java

13

Click here to load reader

Upload: muthukumaran-subramanian

Post on 26-May-2015

95 views

Category:

Education


0 download

DESCRIPTION

general introduction to calendar and gregoriancalendar class in java

TRANSCRIPT

Page 1: Calendar class in java

Java.util package

Page 2: Calendar class in java

Calendar and Gregorian Calendar

Page 3: Calendar class in java

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.

Page 4: Calendar class in java

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.

Page 5: Calendar class in java

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.

Page 6: Calendar class in java

Example program using the Calendar class

Page 7: Calendar class in java

Output for program using Calendar class

Page 8: Calendar class in java

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.

Page 9: Calendar class in java

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

Page 10: Calendar class in java

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.

Page 11: Calendar class in java

Example program for GregorianCalendar class

Page 12: Calendar class in java

Output for GregorianCalendar program

Page 13: Calendar class in java

Thank you