![]() |
VOOZH | about |
In Java, the Calendar class represents a specific moment in time and provides methods to extract individual date and time fields. One most commonly used method of the Calendar class is get(int field) method. This method returns the value of a given calendar field, such as year, month, or day.
In this article, we are going to learn about the Calendar.get() method in Java.
public int get(int field)
Important Points:
Example 1: Current Date Values
Current Date: 2025-5-7
Explanation:
Example 2: Specific Date
Set Date: 2023-7-21
Field Constant | Description | Usage |
|---|---|---|
Calendar.YEAR | Year, for example, 2025 | Retrievs the year |
Calendar.MONTH | Month (0-11) | Retrievs the month |
Calendar.DATE | Day of month (1-31) | Retrievs the day of month |
Calendar.HOUR_OF_DAY | Hour in 24 hour format | Retrievs the hour |
Calendar.MINUTE | Minute (0-59) | Retrievs the minute |
Calendar.SECOND | Second (0-59) | Retrievs the second |
Reference:https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#get(int)