Calendar Class in Java

Spread the love
  • 29
  • 34
  • 14
  • 12
  • 12

Calendar in Java
Calendar in Java

Calendar Class in Java:

Calendar class is an abstract class which provides several methods to perform date and time arithmetic. Calendar class also helps to convert dates and time to and from the millisecond format used by other Date class. The format can be minutes,hours,days,weeks, year. All these format can be either consumable by human or machine.
We can not directly instantiate Calendar class, it provides getInstance() method to get the default locale or default time zone or a specific locale or a specific timezone.

The Structure of the Calendar class is given as:

public abstract class Calendar extends Object implements Serializable, Cloneable {
protected Calendar();
protected Calendar(TimeZone zone, Locale aLocale);
// Constants
public static final int FIELD_COUNT;
// Member elements -Date anf Time Field constants
public static final int ERA;
public static final int YEAR;
public static final int MONTH;
public static final int WEEK_OF_YEAR, WEEK_OF_MONTH;
public static final int DATE, DAY_OF_MONTH;
public static final int DAY_OF_YEAR, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH;
public static final int ZONE_OFFSET, DST_OFFSET;
public static final int AM_PM;
public static final int HOUR, HOUR_OF_DAY;
public static final int MINUTE;
public static final int SECOND;
public static final int MILLISECOND;
public static final int JANUARY, FEBRUARY, MARCH, APRIL;
public static final int MAY, JUNE, JULY, AUGUST;
public static final int UNDECIMBER;
public static final int SUNDAY, MONDAY, TUESDAY, WEDNESDAY;
public static final int THURSDAY, FRIDAY, SATURDAY;
public static final int AM, PM;
protected boolean areFieldsSet;
protected int[] fields;
protected boolean[] isSet;
protected boolean isTimeSet;
protected long time;
public static synchronized Locale[] getAvailableLocales();
public static synchronized Calendar getInstance();
public static synchronized Calendar getInstance(TimeZone zone);
public static synchronized Calendar getInstance(Locale aLocale);
public static synchronized Calendar getInstance(TimeZone zone, Locale aLocale);
public abstract void add(int field, int amount);
public abstract boolean after(Object when);
public abstract boolean before(Object when);
public final void clear();
public final void clear(int field);
public Object clone(); // Overrides Object
public abstract boolean equals(Object when); 
public final int get(int field);
public int getFirstDayOfWeek();
public abstract int getGreatestMinimum(int field);
public abstract int getLeastMaximum(int field);
public abstract int getMaximum(int field);
public int getMinimalDaysInFirstWeek();
public abstract int getMinimum(int field);
public final Date getTime();
public TimeZone getTimeZone();
public boolean isLenient();
public final boolean isSet(int field);
public abstract void roll(int field, boolean up);
public final void set(int field, int value);
public final void set(int year, int month, int date);
public final void set(int year, int month, int date, int hour, int minute);
public final void set(int year, int month, int date, int hour, int minute, int second);
public void setFirstDayOfWeek(int value);
public void setLenient(boolean lenient);
public void setMinimalDaysInFirstWeek(int value);
public final void setTime(Date date);
public void setTimeZone(TimeZone value);
protected void complete();
protected abstract void computeFields();
protected abstract void computeTime();
protected long getTimeInMillis();
protected final int internalGet(int field);
protected void setTimeInMillis(long millis);
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 29
  • 34
  • 14
  • 12
  • 12
READ  SCJP/OCPJCP Certification and Java Programmer


Please enter your comment!
Please enter your name here