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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.math.BigInteger.modInverse() method in Java
- Java.lang.string.replace() method in Java
- Java Clock tickMinutes() method in Java with Examples
- Java.math.BigInteger.probablePrime() method in Java
- Java.util.ArrayList.addall() method in Java
- Java Clock withZone() method in Java with Examples
- Java 8 | ArrayDeque removeIf() method in Java with Examples
- Java.util.BitSet.set() method in Java
- Java.util.ArrayList.add() Method in Java
- Method Class | getAnnotatedReturnType() method in Java
- Method Class | getTypeParameters() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.