Java Calendar Hour sameHour(Calendar one, Calendar two)

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

Description

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

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, day and hour.

Declaration

public static boolean sameHour(Calendar one, Calendar two) 

Method Source Code


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

import java.util.Calendar;

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

    /**
     * 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. hourFloor(Calendar calendar)
  2. hoursInDay(Calendar cal)
  3. moveHoursHand(int aNumberOfHours, Calendar aCalendar)
  4. moveToCalendarHourJust(Calendar cal)
  5. moveToCalendarHourTerminal(Calendar cal)
  6. setCalendar(int hour, int mins)
  7. setDateToZeroHour(Calendar calendar)
  8. setHourMinSecAsNull(Calendar calendar)
  9. setHours(int i, Calendar calendar)