We can get day, month and year from date object in Calendar. Calendar class gives us option to get day, month, and year separately in integer value. We have to use get() method of the calendar and pass value according to what we required in day, month or year from date.
Example of getting day, month and year in date
import java.util.Calendar; public class GetDate { public static void main(String[] args) { Calendar ca1 = Calendar.getInstance(); /// get day month year from set date ca1.set(2009, 05, 15); // dont set this date if current date is required int iDay=ca1.get(Calendar.DATE); int iMonth=ca1.get(Calendar.MONTH); // In Current date Add 1 in month int iYear=ca1.get(Calendar.YEAR); System.out.println("Day :"+iDay); System.out.println("Month :"+iMonth); System.out.println("Year :"+iYear); } }
Output shown
Day :15
Month :5
Year :2009




Link to Us