Here you can find the source of compare(Date start, Date end)
public static int compare(Date start, Date end)
//package com.java2s; /**/*w ww .j a v a 2 s. com*/ * Copyright 2008 - 2011 Simcore.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 { public static int compare(Date start, Date end) { Calendar c1 = Calendar.getInstance(); c1.setTime(start); Calendar c2 = Calendar.getInstance(); c2.setTime(end); int year1 = c1.get(Calendar.YEAR); int year2 = c2.get(Calendar.YEAR); if (year1 != year2) { return year1 - year2; } int month1 = c1.get(Calendar.MONTH); int month2 = c2.get(Calendar.MONTH); if (month1 != month2) { return month1 - month2; } int day1 = c1.get(Calendar.DAY_OF_MONTH); int day2 = c2.get(Calendar.DAY_OF_MONTH); return day1 - day2; } }