Here you can find the source of compareYMD(Date begindate, Date enddate)
Parameter | Description |
---|---|
begindate | begin date |
enddate | end date |
public static boolean compareYMD(Date begindate, Date enddate)
//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; } }