Java Calendar Day isSameDay(Calendar cal1, Calendar cal2)

Here you can find the source of isSameDay(Calendar cal1, Calendar cal2)

Description

is Same Day

License

Apache License

Declaration

public static boolean isSameDay(Calendar cal1, Calendar cal2) 

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 isSameDay(Date date1, Date date2) {
        return isSameDay(toCalendar(date1), toCalendar(date2));
    }/*from   w  w  w  .  j  av a2  s  .c o  m*/

    public static boolean isSameDay(Calendar cal1, Calendar cal2) {
        int year1 = cal1.get(Calendar.YEAR);
        int day1 = cal1.get(Calendar.DAY_OF_YEAR);

        int year2 = cal2.get(Calendar.YEAR);
        int day2 = cal2.get(Calendar.DAY_OF_YEAR);

        if (year1 != year2) {
            return false;
        }

        if (day1 != day2) {
            return false;
        }
        return true;
    }

    public static Calendar toCalendar(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    }
}

Related

  1. isSameDay(Calendar cal1, Calendar cal2)
  2. isSameDay(Calendar cal1, Calendar cal2)
  3. isSameDay(Calendar cal1, Calendar cal2)
  4. isSameDay(Calendar cal1, Calendar cal2)
  5. isSameDay(Calendar cal1, Calendar cal2)
  6. isSameDay(Calendar day1, Calendar day2)
  7. isSameDay(Calendar dayOne, Calendar dayTwo)
  8. isSameDay(Calendar today, Date now)
  9. isSameDay(final Calendar cal1, final Calendar cal2)