Java Calendar Day isSameDay(Calendar cal1, Calendar cal2)

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

Description

Check to see if two Calendars are on the same Day, by comparing the year, month and date

License

Open Source License

Parameter

Parameter Description
cal1 Calendar to compare to cal2
cal2 Calendar to compare to cal1

Return

true if both Calendars are on the same day

Declaration

public static boolean isSameDay(Calendar cal1, Calendar cal2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    /**/*from   w  ww  .  j  a  v a 2 s. c o m*/
     * Check to see if two Calendars are on the same Day, by comparing
     * the year, month and date
     * @param cal1 Calendar to compare to cal2
     * @param cal2 Calendar to compare to cal1
     * @return true if both Calendars are on the same day
     */
    public static boolean isSameDay(Calendar cal1, Calendar cal2) {
        int year1 = cal1.get(Calendar.YEAR);
        int year2 = cal2.get(Calendar.YEAR);

        if (year1 == year2) {
            int month1 = cal1.get(Calendar.MONTH);
            int month2 = cal2.get(Calendar.MONTH);

            if (month1 == month2) {
                int day1 = cal1.get(Calendar.DAY_OF_MONTH);
                int day2 = cal2.get(Calendar.DAY_OF_MONTH);

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

        return false;
    }
}

Related

  1. isHolyday(Calendar c)
  2. isRestDay(Calendar cal)
  3. isSameDay(Calendar c1, Calendar c2)
  4. isSameDay(Calendar cal1, Calendar cal2)
  5. isSameDay(Calendar cal1, Calendar cal2)
  6. isSameDay(Calendar cal1, Calendar cal2)
  7. isSameDay(Calendar cal1, Calendar cal2)
  8. isSameDay(Calendar cal1, Calendar cal2)
  9. isSameDay(Calendar cal1, Calendar cal2)