Java – Calendar & Gregorian class

Java – Calendar & Gregorian class 2017-08-09T12:27:10+00:00

Calendar & Gregorian class :

The Calendar class allows you to interpret date and time information.

This class defines several integer constants that are used when you get or set components of the calendar. These are listed here.

 

AM AM_PM APRIL
AUGUST DATE DAY_OF_MONTH
DAY_OF_WEEK DAY_OF_WEEK_IN_MONTH DAY_OF_YEAR
DECEMBER DST_OFFSET ERA
FEBRUARY FIELD_COUNT FRIDAY
HOUR HOUR_OF_DAY JANUARY
JULY JUNE MARCH
MAY MILLISECOND MINUTE
MONDAY MONTH NOVEMBER
OCTOBER PM SATURADAY
SECOND SEPTEMBER SUNDAY
THURSDAY TUESDAY UNDERIMBER
WEDNESDAY WEEK_OF_MONTH WEEK_OF_YEAR
YEAR ZONE_OFFSET The Calendar class does not have public constructors. Instead, you may use the static getInstance() method to obtain a calendar initialized to the current date and time.

 

One of its forms is shown here:

Calendar getInstance()

EX :

?

 


Output :
DATE is : 23
YEAR is : 2012
MONTH is : 9
DAY OF WEEK is : 3
WEEK OF MONTH is : 4
DAY OF YEAR is : 297
DAY OF MONTH is : 23
WEEK OF YEAR is : 43
HOUR is : 2
MINUTE is : 32
SECOND is : 32
DAY OF WEEK IN MONTH is : 4
Era is : 1
HOUR OF DAY is : 14
MILLISECOND : 595
AM_PM : 1
  • The GregorianCalendar class is a subclass of Calendar.
  • It provides the logic to manage date and time information according to the rules of the Gregorian calendar.
  • This class provides following constructors:

GregorianCalendar()

GregorianCalendar(int year, int month, int date)

GregorianCalendar(int year, int month, int date, int hour, int minute, int sec)

GregorianCalendar(int year, int month, int date, int hour, int minute)

  • The first form creates an object initialized with the current date and time.
  • The other forms allow you to specify how various date and time components are initialized.
  • The class provides all of the method defined by Calendar and also adds the isLeapYear() method shown here:

Boolean isLeapYear()

This method returns true if the current year is a leap year. Otherwise, it returns false.

EX :

?

 


Output :
Is leap yer true
DATE is : 23
YEAR is : 2012
MONTH is : 9
DAY OF WEEK is : 3
WEEK OF MONTH is : 4
DAY OF YEAR is : 297
DAY OF MONTH is : 23
WEEK OF YEAR is : 43
HOUR is : 2
MINUTE is : 37
SECOND is : 26
DAY OF WEEK IN MONTH is : 4
Era is : 1
HOUR OF DAY is : 14
MILLISECOND : 939
AM_PM : 1

Prev Next