Java Date Compare compareYMD(Date begindate, Date enddate)

Here you can find the source of compareYMD(Date begindate, Date enddate)

Description

add by xie compare date only compare year month day

License

Open Source License

Parameter

Parameter Description
begindate begin date
enddate end date

Return

begindate > endate as false

Declaration

public static boolean compareYMD(Date begindate, Date enddate) 

Method Source Code


//package com.java2s;
/*/*ww w.  j a  va  2 s  . c om*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.util.Date;
import java.util.Calendar;

public class Main {
    /**
     * add by xie compare date only compare year month day
     *
     * @param begindate begin date
     * @param enddate   end date
     * @return begindate > endate as false
     */
    public static boolean compareYMD(Date begindate, Date enddate) {
        boolean isBefore = true;
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(begindate);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(enddate);
        int startYear = startCalendar.get(Calendar.YEAR);
        int startMonth = startCalendar.get(Calendar.MONTH);
        int startDay = startCalendar.get(Calendar.DAY_OF_MONTH);
        int endYear = endCalendar.get(Calendar.YEAR);
        int endMonth = endCalendar.get(Calendar.MONTH);
        int endDay = endCalendar.get(Calendar.DAY_OF_MONTH);
        if (startYear > endYear) {
            isBefore = false;
        } else if (startYear == endYear) {
            if (startMonth > endMonth) {
                isBefore = false;
            } else if (startMonth == endMonth) {
                if (startDay > endDay) {
                    isBefore = false;
                }
            }
        }
        return isBefore;
    }
}

Related

  1. compareTo(Date src, Date dest)
  2. compareToCal(Date sDate, Date eDate)
  3. compareToMonthByDate(Date startDate, Date endDate)
  4. compareTwoDate(Date beforeDate, Date afterDate)
  5. compareYear(java.util.Date date1, java.util.Date date2)
  6. compDate(Date date1, Date date2)
  7. compDate4(Date date1, Date date2)
  8. getCompareDate(Date startDate, Date endDate)
  9. getCompareDate(String strDate1, String strDate2, String pFormat)