Calendar.get() Method in Java
java.util.Calendar.get() method is a method of java.util.Calendar class. The Calendar class provides some methods for implementing a concrete calendar system outside the package. Some examples of Calendar fields are : YEAR, DATE, MONTH, DAY_OF_WEEK, DAY_OF_YEAR, WEEK_OF_YEAR, MINUTE, SECOND, HOUR, AM_PM, WEEK_OF_MONTH, DAY_OF_WEEK_IN_MONTH, HOUR_OF_DAY.
public int get(int field) where, field represents the given calendar field and the function returns the value of given field.
Exception : If the specified field is out of range, then ArrayIndexOutOfBoundsException is thrown.
Example 1: To fetch Date, Month, Year
Day : 1 Month : 2 Year : 2018
Example 2 : To fetch Day of the week, Day of the year, Week of the month, Week of the year.
Day of week : 5 Day of year : 60 Week in Month : 1 Week in Year : 9 Day of Week in Month : 1
Example 3 : To fetch Hour, Minute, Second and AM_PM.
Hour : 6 Minute : 51 Second : 53 AM or PM : 0 Hour (24-hour clock) : 6
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.