Java Date Compare by Month isSameMonth(final Date date1, final Date date2)

Here you can find the source of isSameMonth(final Date date1, final Date date2)

Description

is Same Month

License

Apache License

Declaration

public static boolean isSameMonth(final Date date1, final Date date2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static boolean isSameMonth(final Date date1, final Date date2) {
        final Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);// ww w .j  ava  2 s.  co  m
        final Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);
        if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) {
            return false;
        }
        return cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
    }
}

Related

  1. isSameMonth(Date date1, Date date2)
  2. isSameMonth(Date date1, Date date2)
  3. isSameMonth(final Date d1, final Date d2)
  4. monthsBetween(Date firstDate, Date secondDate)
  5. monthsBetween(final Date von, final Date bis)
  6. sameMonth(Date date1, Date date2)
  7. sameMonth(Date date1, Date date2)