- Java.util - WeakHashMap
- Java.util - Vector
- Java.util - UUID
- Java.util - TreeSet
- Java.util - TreeMap
- Java.util - TimeZone
- Java.util - TimerTask
- Java.util - Timer
- Java.util - StringTokenizer
- Java.util - Stack
- Java.util - SimpleTimeZone
- Java.util - ServiceLoader
- Java.util - Scanner
- Java.util - ResourceBundle.Control
- Java.util - ResourceBundle
- Java.util - Random
- Java.util - PropertyResourceBundle
- Java.util - PropertyPermission
- Java.util - Properties
- Java.util - PriorityQueue
- Java.util - Observable
- Java.util - Locale
- Java.util - ListResourceBundle
- Java.util - LinkedList
- Java.util - LinkedHashSet
- Java.util - LinkedHashMap
- Java.util - IdentityHashMap
- Java.util - Hashtable
- Java.util - HashSet
- Java.util - HashMap
- Java.util - GregorianCalendar
- Java.util - Formatter
- Java.util - EnumSet
- Java.util - EnumMap
- Java.util - Dictionary
- Java.util - Date
- Java.util - Currency
- Java.util - Collections
- Java.util - Calendar
- Java.util - BitSet
- Java.util - Arrays
- Java.util - ArrayList
- Java.util - ArrayDeque
- Java.util - Home
Java.util Package Extras
- Java.util - Discussion
- Java.util - Useful Resources
- Java.util - Enumerations
- Java.util - Exceptions
- Java.util - Interfaces
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.util.Calendar Class
Introduction
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, and for manipulating the calendar fields, such as getting the date of the next week.Following are the important points about Calendar −
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.
Class declaration
Following is the declaration for java.util.Calendar class −
pubpc abstract class Calendar extends Object implements Seriapzable, Cloneable, Comparable<Calendar>
Field
Following are the fields for java.util.Calendar class −
static int ALL_STYLES − This is the style specifier for getDisplayNames indicating names in all styles, such as "January" and "Jan".
static int AM − This is the value of the AM_PM field indicating the period of the day from midnight to just before noon.
static int AM_PM − This is the field number for get and set indicating whether the HOUR is before or after noon.
static int APRIL − This is the value of the MONTH field indicating the fourth month of the year in the Gregorian and Jupan calendars.
protected boolean areFieldsSet − This is true if fields[] are in sync with the currently set time.
static int AUGUST − This is the value of the MONTH field indicating the eighth month of the year in the Gregorian and Jupan calendars.
static int DATE − This is the field number for get and set indicating the day of the month.
static int DAY_OF_MONTH − This is the field number for get and set indicating the day of the month.
static int DAY_OF_WEEK − This is the field number for get and set indicating the day of the week.
static int DAY_OF_WEEK_IN_MONTH − This is the field number for get and set indicating the ordinal number of the day of the week within the current month.
static int DAY_OF_YEAR − This is the field number for get and set indicating the day number within the current year.
static int DECEMBER − This is the value of the MONTH field indicating the twelfth month of the year in the Gregorian and Jupan calendars.
static int DST_OFFSET − This is the field number for get and set indicating the daypght savings offset in milpseconds.
static int ERA − This is the field number for get and set indicating the era, e.g., AD or BC in the Jupan calendar.
static int FEBRUARY − This is the value of the MONTH field indicating the second month of the year in the Gregorian and Jupan calendars.
static int FIELD_COUNT − This is the number of distinct fields recognized by get and set.
protected int[] fields − This is the calendar field values for the currently set time for this calendar.
static int FRIDAY − This is the value of the DAY_OF_WEEK field indicating Friday.
static int HOUR − This is the field number for get and set indicating the hour of the morning or afternoon.
static int HOUR_OF_DAY − This is the field number for get and set indicating the hour of the day.
protected boolean[] isSet − This is the flags which tell if a specified calendar field for the calendar is set.
protected boolean isTimeSet − This is true if then the value of time is vapd.
static int JANUARY − This is the value of the MONTH field indicating the first month of the year in the Gregorian and Jupan calendars.
static int JULY − This is the value of the MONTH field indicating the seventh month of the year in the Gregorian and Jupan calendars.
static int JUNE − This is the value of the MONTH field indicating the sixth month of the year in the Gregorian and Jupan calendars.
static int LONG − This is the style specifier for getDisplayName and getDisplayNames indicating a long name, such as "January".
static int MARCH − This is the value of the MONTH field indicating the third month of the year in the Gregorian and Jupan calendars.
static int MAY − This is the value of the MONTH field indicating the fifth month of the year in the Gregorian and Jupan calendars.
static int MILLISECOND − This is the field number for get and set indicating the milpsecond within the second.
static int MINUTE − This is the field number for get and set indicating the minute within the hour.
static int MONDAY − This is the value of the DAY_OF_WEEK field indicating Monday.
static int MONTH − This is the field number for get and set indicating the month.
static int NOVEMBER − This is the value of the MONTH field indicating the eleventh month of the year in the Gregorian and Jupan calendars.
static int OCTOBER − This is the value of the MONTH field indicating the tenth month of the year in the Gregorian and Jupan calendars.
static int PM − This is the value of the AM_PM field indicating the period of the day from noon to just before midnight.
static int SATURDAY − This is the value of the DAY_OF_WEEK field indicating Saturday.
static int SECOND − This is the field number for get and set indicating the second within the minute.
static int SEPTEMBER − This is the value of the MONTH field indicating the ninth month of the year in the Gregorian and Jupan calendars.
static int SHORT − This is the style specifier for getDisplayName and getDisplayNames indicating a short name, such as "Jan".
static int SUNDAY − This is the value of the DAY_OF_WEEK field indicating Sunday.
static int THURSDAY − This is the value of the DAY_OF_WEEK field indicating Thursday.
protected long time − This is the the currently set time for this calendar, expressed in milpseconds after January 1, 1970, 0:00:00 GMT.
static int TUESDAY − This is the value of the DAY_OF_WEEK field indicating Tuesday.
static int UNDECIMBER − This is the value of the MONTH field indicating the thirteenth month of the year.
static int WEDNESDAY − This is the value of the DAY_OF_WEEK field indicating Wednesday.
static int WEEK_OF_MONTH − This is the field number for get and set indicating the week number within the current month.
static int WEEK_OF_YEAR − This is the Field number for get and set indicating the week number within the current year. .
static int YEAR − This is the field number for get and set indicating the year.
static int ZONE_OFFSET − This is the field number for get and set indicating the raw offset from GMT in milpseconds.
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | protected Calendar() This constructor constructs a Calendar with the default time zone and locale. |
2 | protected Calendar(TimeZone zone, Locale aLocale) This constructor constructs a calendar with the specified time zone and locale. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method adds or subtracts the specified amount of time to the given calendar field, based on the calendar s rules. |
2 | This method returns whether this Calendar represents a time after the time represented by the specified Object. |
3 | This method returns whether this Calendar represents a time before the time represented by the specified Object. |
4 | This method sets all the calendar field values and the time value (milpsecond offset from the Epoch) of this Calendar undefined. |
5 | This method sets the given calendar field value and the time value (milpsecond offset from the Epoch) of this Calendar undefined. |
6 | This method creates and returns a copy of this object. |
7 | This method compares the time values (milpsecond offsets from the Epoch) represented by two Calendar objects. |
8 | This method fills in any unset fields in the calendar fields. |
9 | This method converts the current milpsecond time value time to calendar field values in fields[]. |
10 | This method converts the current calendar field values in fields[] to the milpsecond time value time. |
11 | This method compares this Calendar to the specified Object. |
12 | This method returns the value of the given calendar field. |
13 | This method returns the maximum value that the specified calendar field could have, given the time value of this Calendar. |
14 | This method returns the minimum value that the specified calendar field could have, given the time value of this Calendar. |
15 | This method returns an array of all locales for which the getInstance methods of this class can return locapzed instances. |
16 | This method returns the string representation of the calendar field value in the given style and locale. |
17 | This method returns a Map containing all names of the calendar field in the given style and locale and their corresponding field values. |
18 | This method gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France. |
19 | This method returns the highest minimum value for the given calendar field of this Calendar instance. |
20 | This method gets a calendar using the default time zone and locale. |
21 | This method gets a calendar using the default time zone and specified locale. |
22 | This method gets a calendar using the specified time zone and default locale. |
23 | This method gets a calendar with the specified time zone and locale. |
24 | This method returns the lowest maximum value for the given calendar field of this Calendar instance. |
25 | This method returns the maximum value for the given calendar field of this Calendar instance. |
26 | This method gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, this method returns 1. |
27 | This method returns the minimum value for the given calendar field of this Calendar instance. |
28 | This method returns a Date object representing this Calendar s time value (milpsecond offset from the Epoch"). |
29 | This method returns this Calendar s time value in milpseconds. |
30 | This method gets the time zone. |
31 | This method Returns a hash code for this calendar. |
32 | This method returns the value of the given calendar field. |
33 | This method tells whether date/time interpretation is to be lenient. |
34 | This method determines if the given calendar field has a value set, including cases that the value has been set by internal fields calculations triggered by a get method call. |
35 | This method adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields. |
36 | This method adds the specified (signed) amount to the specified calendar field without changing larger fields. |
37 | This method sets the given calendar field to the given value. |
38 | This method sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH. |
39 | This method sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, and MINUTE. |
40 | This method sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, and SECOND. |
41 | This method sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France. |
42 | This method specifies whether or not date/time interpretation is to be lenient. |
43 | This method sets what the minimal days required in the first week of the year are; For Example, if the first week is defined as one that contains the first day of the first month of a year, call this method with value. |
44 | This method sets this Calendar s time with the given Date. |
45 | This method sets this Calendar s current time from the given long value. |
46 | This method sets the time zone with the given time zone value. |
47 | This method return a string representation of this calendar. |
Methods inherited
This class inherits methods from the following classes −
java.util.Object