Java Calendar Day isSameDay(Calendar cal1, Calendar cal2)

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

Description

Returns whether the two specified times are on the same day

License

Open Source License

Parameter

Parameter Description
cal1 the first time
cal2 the second time

Return

true if the two specified times are on the same day; false otherwise

Declaration

public static boolean isSameDay(Calendar cal1, Calendar cal2) 

Method Source Code

//package com.java2s;
/*//w  w  w .  ja  va  2s . c o m
 * Copyright SparseWare Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Calendar;

public class Main {
    /**
     * Returns whether the two specified times are on the same day
     * @param cal1 the first time
     * @param cal2 the second time
     * @return true if the two specified times are on the same day; false otherwise
     */
    public static boolean isSameDay(Calendar cal1, Calendar cal2) {
        if (cal1.get(Calendar.DAY_OF_YEAR) != cal2
                .get(Calendar.DAY_OF_YEAR)) {
            return false;
        }

        if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) {
            return false;
        }

        return true;
    }
}

Related

  1. isSameDay(Calendar c1, Calendar c2)
  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 cal1, Calendar cal2)
  7. isSameDay(Calendar cal1, Calendar cal2)
  8. isSameDay(Calendar day1, Calendar day2)
  9. isSameDay(Calendar dayOne, Calendar dayTwo)