Here you can find the source of compareMonth(Date first, Date second)
Parameter | Description |
---|---|
targetMonth | a parameter |
newTargetMonth | a parameter |
public static int compareMonth(Date first, Date second)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**/*from w ww. ja va2 s .c om*/ * @param targetMonth * @param newTargetMonth * @return */ public static int compareMonth(Date first, Date second) { Calendar cf = Calendar.getInstance(); cf.setTime(first); Calendar cs = Calendar.getInstance(); cs.setTime(second); int offset = (cs.get(Calendar.YEAR) - cf.get(Calendar.YEAR)) * 12 + (cs.get(Calendar.MONTH) - cf.get(Calendar.MONTH)); return offset; } }