Thursday, 5 April 2012

Class - Calendar And Gregorian Calendar


Calendar

The abstract calendar class provides a set of methods that allows to convert a time in milliseconds to number of useful components. The type of information that can be provide are: Year,Month,Day,Hour,Minute and second.
 
Calendar provides no public constructors. Instead, getInstance() method is used to obtain a calendar initialized to the current date and time.

Calendar defines several protected instance variables are Fieldset is a boolean that indicates if the time components have been set. Fields is an array of that holds the components of the time isSet is a boolean array that indicates if a specific time component has been set. Time is a long that holds the current time for this object isTimeSet is a boolean that indicates if the current time has been set.

Calendar defines the following int constants, which are used when you get or set

Components of the calendar:

AM
NOVEMBER
PM
DECEMBER
AM_PM                 
DATE
SUNDAY
DAY_OF_MONTH
MONDAY
DAY_OF_WEEK
TUESDAY
DAY_OF_WEEK_IN_MONTH
WEDNESDAY
DAY_OF_YEAR
THURSDAY
MONTH
FRIDAY
WEEK_OF_MONTH
SATURDAY
WEEK_OF_YEAR
JANUARY
HOUR
FEBRUARY
MINUTE
MARCH
SECOND
APRIL
MILLISECOND
MAY
HOUR_OF_DAY
JUNE
YEAR
JULY
ZONE_OFFSET
AUGUST
FIELD_COUNT
SEPTMBER
DST_OFFSET        
OCTOBER
ERA
                                                                                                                                                                                                                                                                                                                                                                

Methods:

Static calendar getInstance()
Returns a calendar object for the default locale and time Zone.

abstract void add(int which,int val)
Adds val to the time or date components specified by which to subtract, add a negative value which must be one of the fields defined by calendar such as calendar. HOUR

boolean after(object calendar obj)
Returns true if the invoking calendar object contains a date that is later than the once specified by calendar obj. otherwise , it returns false.

boolean before(object calendar obj)
Returns true if the invoking calendar object contains a date that is before than the once specified by calendar obj. otherwise , it returns false.

final void clear()
            Zeros all time components in the invoking object.

boolean equals(object calenderObj)
Returns true if the invoking calendar object contains a date that is equal to the one specified by calendarObj. Otherwise it returns false.

final int get(int calendar Field)
Returns the value of one component of the invoking object. The component is indicated by calendarField. Examples of the components that can be requested are calendar. Year,calendar. Month,calendar. Minute and so fourth.

TimeZone getTimeZone()
            Returns the timeZone for the invoking object.

Final void set (int year, int month, int dayOfMonth, int hours, int minutes, int seconds)
Sets various date and time components of the invoking object.

void setTimeZone(TimeZone tz)
Sets the time zone for the invoking object to that specified by tz.

Gregorian Calendar

  Gregorian calendar is a concrete implementation of a calendar. The getInstance() method of calendar returns a GregorianCalendar. initialized with the current date and time in the default locale and time zone.
  Gregorian calendar defines two fields: AD and BC. These represent the two defined by the Gregorian calendar.
  There are also several constructors for GregorianCalendar objects.
GregorianCalendar()
The default, initializes the object with the current date and time in the default locale and time zone. Three constructors offer increasing levels of specificity.

GregorianCalendar(int Year, int month,int dayofMonth)
GregorianCalendar(int year,int month,int dayofMonth)     
GregorianCalendar(int year,int month,int dayofMonth,int hours,int minutes,int seconds)

All three versions set the day,month and year.
Here, year specifies the number of years that have elapsed since 1900.the month is specified  by month with zero indicating january.The day of month is specified by day of month.
The first version sets the time to midnight.The second version also sets the hours and the minutes.
The third version adds second.
  The following constructors create objects initialized with the current date and time using specified time zone and/or locale.
  GregorianCalendar (Locale locale)
  GregorianCalendar (Timezone timezone)
  GregorianCalendar (Timezone timezone,Locale locale)
GregorianCalendar provides an implementation of all the abstract methods in calendar.

Method 

Boolean isLeapyear(int year)
This method returns true if year is a leapyear and otherwise returns false.


Posted By : Ruchita APnday

3 comments:

  1. I'm Serenity Autumn, currently living in Texas city, USA. I am a widow at the moment with Four kids and i was stuck in a financial situation in May 2019 and i needed to refinance and pay my bills. I tried seeking loans from various loan firms both private and corporate but never with success, and most banks declined my credit. But as God would have it, I was introduced to a woman of God a private loan lender who gave me a loan of 850,000.00 USD and today am a business owner and my kids are doing well at the moment, if you must contact any firm with reference to securing a loan without collateral , no credit check, no co signer with just 2% interest rate and better repayment plans and schedule, please contact Mrs Mr Bejamin Lee On Email 247officedept@gmail.com   And Whats-App +1-989-394-3740. He doesn't know that am doing this but am so happy now and i decided to let people know more about him and also i want God to bless him more.

    ReplyDelete