Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Calendar class in java

730 views

Published on

general introduction to calendar and gregoriancalendar class in java

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Calendar class in java

  1. 1. Java.util package
  2. 2. Calendar and Gregorian Calendar
  3. 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. 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. 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.
  6. 6. Example program using the Calendar class
  7. 7. Output for program using Calendar class
  8. 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. 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. 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.
  11. 11. Example program for GregorianCalendar class
  12. 12. Output for GregorianCalendar program
  13. 13. Thank you

×