Java Date Compare compareMonth(Date first, Date second)

Here you can find the source of compareMonth(Date first, Date second)

Description

compare Month

License

Open Source License

Parameter

Parameter Description
targetMonth a parameter
newTargetMonth a parameter

Declaration

public static int compareMonth(Date first, Date second) 

Method Source Code

//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;
    }
}

Related

  1. compareDateTimeNull(Date d1, Date d2)
  2. compareDay(Date date, Date anotherDate)
  3. compareDay(Date date1, int compday)
  4. compareDays(final Date date1, final Date date2)
  5. compareFileDates(final Date date1, final Date date2)
  6. compareSecond(java.util.Date date1, java.util.Date date2)
  7. compareStartDateEndDate(String startDate, String endDate)
  8. compareTime(Date date1, Date date2)
  9. compareTime(Date first, Date second)