Java Calendar Month sameMonth(Calendar one, Calendar two)

Here you can find the source of sameMonth(Calendar one, Calendar two)

Description

Returns true if the two given calendars are dated on the same year and month.

License

Apache License

Parameter

Parameter Description
one The one calendar.
two The other calendar.

Return

True if the two given calendars are dated on the same year and month.

Declaration

public static boolean sameMonth(Calendar one, Calendar two) 

Method Source Code


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

import java.util.Calendar;

public class Main {
    /**//from  w w w  .ja v  a  2s.c  om
     * Returns <tt>true</tt> if the two given calendars are dated on the same year and month.
     * @param one The one calendar.
     * @param two The other calendar.
     * @return True if the two given calendars are dated on the same year and month.
     */
    public static boolean sameMonth(Calendar one, Calendar two) {
        return one.get(Calendar.MONTH) == two.get(Calendar.MONTH) && sameYear(one, two);
    }

    /**
     * Returns <tt>true</tt> if the two given calendars are dated on the same year.
     * @param one The one calendar.
     * @param two The other calendar.
     * @return True if the two given calendars are dated on the same year.
     */
    public static boolean sameYear(Calendar one, Calendar two) {
        return one.get(Calendar.YEAR) == two.get(Calendar.YEAR);
    }
}

Related

  1. isFirstDayOfMonth(Calendar calendar)
  2. lastDayOfMonth(Calendar c)
  3. month(Calendar calendar)
  4. month(Calendar date)
  5. numberOfDaysInMonth(Calendar cal)
  6. setDate(Calendar cal, int month, int date)
  7. setDate(Calendar cal, int month, int date, boolean endOfDay)
  8. setDate(Calendar calendar, int month, int date)
  9. setTimeAsFirstDayOfMonth(Calendar calendar)