Here you can find the source of compareDatesOnly(long date1, long date2)
Parameter | Description |
---|---|
date1 | the first date to compare |
date2 | the second date to compare with |
public static int compareDatesOnly(long date1, long date2)
//package com.java2s; /*//from w w w.j a v a2s . c om * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. * See terms of license at gnu.org. */ import java.util.*; public class Main { private static final Calendar c1 = Calendar.getInstance(); private static final Calendar c2 = Calendar.getInstance(); /** * Compares the two dates. The comparison is based only on the day, month * and year values. Returns 0 if the two dates are equals, a value < 0 if * the first date is before the second one and > 0 if the first date is * after the second one. * @param date1 the first date to compare * @param date2 the second date to compare with * @return Returns 0 if the two dates are equals, a value < 0 if * the first date is before the second one and > 0 if the first date is * after the second one */ public static int compareDatesOnly(long date1, long date2) { c1.setTimeInMillis(date1); c2.setTimeInMillis(date2); int day1 = c1.get(Calendar.DAY_OF_MONTH); int month1 = c1.get(Calendar.MONTH); int year1 = c1.get(Calendar.YEAR); int day2 = c2.get(Calendar.DAY_OF_MONTH); int month2 = c2.get(Calendar.MONTH); int year2 = c2.get(Calendar.YEAR); if (year1 < year2) { return -1; } else if (year1 == year2) { if (month1 < month2) return -1; else if (month1 == month2) { if (day1 < day2) return -1; else if (day1 == day2) return 0; else return 1; } else return 1; } else { return 1; } } /** * Compares the two dates. The comparison is based only on the day, month * and year values. Returns 0 if the two dates are equals, a value < 0 if * the first date is before the second one and > 0 if the first date is * after the second one. * @param date1 the first date to compare * @param date2 the second date to compare with * @return Returns 0 if the two dates are equals, a value < 0 if * the first date is before the second one and > 0 if the first date is * after the second one */ public static int compareDatesOnly(Date date1, Date date2) { return compareDatesOnly(date1.getTime(), date2.getTime()); } }