Java Date Equal sameDate(Date date1, Date date2)

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

Description

same Date

License

Open Source License

Declaration

public static boolean sameDate(Date date1, Date date2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) Emil Crumhorn - Hexapixel.com - emil.crumhorn@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://ww w .  j  a  v a  2  s.c o  m
 *    emil.crumhorn@gmail.com - initial API and implementation
 *******************************************************************************/

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

public class Main {
    public static boolean sameDate(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();

        cal1.setTime(date1);
        cal2.setTime(date2);

        return sameDate(cal1, cal2);
    }

    public static boolean sameDate(Calendar cal1, Calendar cal2) {
        if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)) {
            if (cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)) {
                return true;
            }
        }

        return false;
    }
}

Related

  1. isSameDate(Date pathDate, Date now)
  2. isSameDate(long var0, long var2)
  3. monthEquals(Date current, Date compare)
  4. nowInDateEquals(Date now, Date d1, Date d2)
  5. sameDate(Date date1, Date date2)
  6. yearMonthsEqual(final Date firstDate, final Date secondDate)