Java Date Compare compareTime(Date first, Date second)

Here you can find the source of compareTime(Date first, Date second)

Description

compare Time

License

Open Source License

Parameter

Parameter Description
first a parameter
second a parameter

Return

the value 0 if first is equal to second; a value less than 0 if first is before second; and a value greater than 0 if first is after second.

Declaration

public static int compareTime(Date first, Date second) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from   w w w  .  j a v a2  s.com*/
     * 
     * @param first
     * @param second
     * @return the value 0 if first is equal to second; a value less than 0 if
     *         first is before second; and a value greater than 0 if first is
     *         after second.
     */
    public static int compareTime(Date first, Date second) {

        Calendar firstCal = new GregorianCalendar();
        firstCal.setTime(first);
        firstCal.set(0, 0, 0);

        Calendar secondCal = new GregorianCalendar();
        secondCal.setTime(second);
        secondCal.set(0, 0, 0);

        return firstCal.compareTo(secondCal);
    }
}

Related

  1. compareFileDates(final Date date1, final Date date2)
  2. compareMonth(Date first, Date second)
  3. compareSecond(java.util.Date date1, java.util.Date date2)
  4. compareStartDateEndDate(String startDate, String endDate)
  5. compareTime(Date date1, Date date2)
  6. compareTimesOfDay(Date time1, Date time2)
  7. compareTo(Date src, Date dest)
  8. compareToCal(Date sDate, Date eDate)
  9. compareToMonthByDate(Date startDate, Date endDate)