Java tutorial
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.util.Date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static int getMonthFromDate(String origDate) { DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); Date date; int month = 1; try { date = formatter.parse(origDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); month = cal.get(Calendar.MONTH); } catch (ParseException e) { e.printStackTrace(); } return month; } }