Android examples for java.util:Month
calculate month counts between startDate and endDate
import java.util.Date; import android.text.format.Time; public class Main { /**//from w w w . ja v a 2s.c o m * calculate month counts between startDate and endDate * * @param startDate * @param endDate * @return */ public static int diffMonths(Date startDate, Date endDate) { Time startTime = new Time(); startTime.set(startDate.getTime()); Time endTime = new Time(); endTime.set(endDate.getTime()); int diffYears = endTime.year - startTime.year; return diffYears * 12 + endTime.month - startTime.month; } }