Java Calendar Day sameDay(Calendar one, Calendar two)

Here you can find the source of sameDay(Calendar one, Calendar two)

Description

Returns true if the two given calendars are dated on the same year, month and day.

License

Apache License

Parameter

Parameter Description
one The one calendar.
two The other calendar.

Return

True if the two given calendars are dated on the same year, month and day.

Declaration

public static boolean sameDay(Calendar one, Calendar two) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

public class Main {
    /**//from www .  j  a va 2 s  . c  o m
     * Returns <tt>true</tt> if the two given calendars are dated on the same year, month and day.
     * @param one The one calendar.
     * @param two The other calendar.
     * @return True if the two given calendars are dated on the same year, month and day.
     */
    public static boolean sameDay(Calendar one, Calendar two) {
        return one.get(Calendar.DATE) == two.get(Calendar.DATE) && sameMonth(one, two);
    }

    /**
     * Returns <tt>true</tt> if the two given calendars are dated on the same year and month.
     * @param one The one calendar.
     * @param two The other calendar.
     * @return True if the two given calendars are dated on the same year and month.
     */
    public static boolean sameMonth(Calendar one, Calendar two) {
        return one.get(Calendar.MONTH) == two.get(Calendar.MONTH) && sameYear(one, two);
    }

    /**
     * Returns <tt>true</tt> if the two given calendars are dated on the same year.
     * @param one The one calendar.
     * @param two The other calendar.
     * @return True if the two given calendars are dated on the same year.
     */
    public static boolean sameYear(Calendar one, Calendar two) {
        return one.get(Calendar.YEAR) == two.get(Calendar.YEAR);
    }
}

Related

  1. moveToCalendarDayJust(Calendar cal)
  2. newCalendarForDay(Date date)
  3. resetToBeginningOfDay(Calendar c)
  4. sameDay(Calendar a, Calendar b)
  5. sameDay(Calendar c1, Calendar c2)
  6. setDayToCalendar(int days, Calendar calendar)
  7. setEndDay(Calendar cal)
  8. setStartOfDay(final Calendar calendar)
  9. setStartTimeOfDay(Calendar calender)