Here you can find the source of isSameDay(Calendar date1, Calendar date2, boolean ignoreYear)
true
if the two specified dates are on the same day of the same month in the same year.
Parameter | Description |
---|---|
date1 | a parameter |
date2 | a parameter |
ignoreYear | If <code>true</code>, ignores year in comparison. |
public static boolean isSameDay(Calendar date1, Calendar date2, boolean ignoreYear)
//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)); } }