Java Date Equal equalDateByDay(Date date1, Date date2)

Here you can find the source of equalDateByDay(Date date1, Date date2)

Description

This is function equalDateByDay Version: 1.0 History: DATE AUTHOR DESCRIPTION ------------------------------------------------- 10-April-2013 Nam Dinh Create new

License

Apache License

Parameter

Parameter Description
date1 a parameter
date2 a parameter

Return

int

Declaration

public static int equalDateByDay(Date date1, Date date2) 

Method Source Code

//package com.java2s;
/*//w  w w .java  2  s .  c  o  m
 * Copyright (c) 2014 by Open eGovPlatform (http://http://openegovplatform.org/).
 * 
 * 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;
import java.util.Date;

public class Main {
    /** 
     * This is function equalDateByDay
     * 
     * Version: 1.0
     *  
     * History: 
     *   DATE        AUTHOR      DESCRIPTION 
     *  ------------------------------------------------- 
     *  10-April-2013  Nam Dinh    Create new
     * @param date1
     * @param date2
     * @return int
     */
    public static int equalDateByDay(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);
        //so sanh theo nam

        if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR)) {
            return 1;
        } else if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) {
            return -1;
        } else {
            //so sanh theo thang
            if (cal1.get(Calendar.MONTH) > cal2.get(Calendar.MONTH)) {
                return 1;
            } else if (cal1.get(Calendar.MONTH) < cal2.get(Calendar.MONTH)) {
                return -1;
            } else {
                //so sanh theo ngay

                if (cal1.get(Calendar.DAY_OF_MONTH) > cal2.get(Calendar.DAY_OF_MONTH)) {
                    return 1;
                } else if (cal1.get(Calendar.DAY_OF_MONTH) < cal2.get(Calendar.DAY_OF_MONTH)) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }

    }
}

Related

  1. areEqual(Date date1, Date date2)
  2. dateEquals(Date dtFirst, Date dtSecond)
  3. datesEqualToSecond(Date date1, Date date2)
  4. equal(Date date, Date other)
  5. equalDates(Date first, Date second)
  6. equalsIgnoreTime(final Date d1, final Date d2)
  7. equalsToDate(Date date1, Date date2, boolean checkTime)
  8. equalsWoTime(final Date date1, final Date date2)