Java Calendar Year isSameDay(Calendar date1, Calendar date2, boolean ignoreYear)

Here you can find the source of isSameDay(Calendar date1, Calendar date2, boolean ignoreYear)

Description

Returns true if the two specified dates are on the same day of the same month in the same year.

License

Open Source License

Parameter

Parameter Description
date1 a parameter
date2 a parameter
ignoreYear If <code>true</code>, ignores year in comparison.

Declaration

public static boolean isSameDay(Calendar date1, Calendar date2, boolean ignoreYear) 

Method Source Code

//package com.java2s;
/*/*from w  ww. j  av a  2 s  .co  m*/
 * Wiki_in_a_jar
 * 
 * Copyright (C) 2007 rico_g AT users DOT sourceforge DOT net
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License s published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * 
 */

import java.util.Calendar;

public class Main {
    /**
     * Returns <code>true</code> if the two specified dates are on the same
     * day of the same month in the same year.
     * 
     * @param date1
     * @param date2
     * @param ignoreYear
     *            If <code>true</code>, ignores year in comparison.
     * @return
     */
    public static boolean isSameDay(Calendar date1, Calendar date2, boolean ignoreYear) {
        return date1.get(Calendar.DAY_OF_MONTH) == date2.get(Calendar.DAY_OF_MONTH)
                && date1.get(Calendar.MONTH) == date2.get(Calendar.MONTH)
                && (ignoreYear || date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR));
    }
}

Related

  1. getYear(Calendar calendar)
  2. getYear(Date date, Calendar cal)
  3. getYearForWeek(final Calendar cal)
  4. getYearList(Calendar currDate)
  5. isBeforeDay(Calendar date1, Calendar date2, boolean ignoreYear)
  6. isSameDayOfYear(Calendar calendar1, Calendar calendar2)
  7. isSameWeekOfYear(Calendar calendar1, Calendar calendar2)
  8. isToThisDayOrLater(int year, int month, int day, java.util.Calendar start, java.util.Calendar end)
  9. isWithinYears(int year, java.util.Calendar start, java.util.Calendar end)