Java: Get month Integer from Date

Muhd picture Muhd · Aug 25, 2011 · Viewed 353.1k times · Source

How do I get the month as an integer from a Date object (java.util.Date)?

Answer

adarshr picture adarshr · Aug 25, 2011
java.util.Date date= new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH);