Java Date Compare compDate4(Date date1, Date date2)

Here you can find the source of compDate4(Date date1, Date date2)

Description

comp Date

License

Apache License

Declaration

public static int compDate4(Date date1, Date date2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static int compDate4(Date date1, Date date2) {
        Calendar ca1 = Calendar.getInstance();
        Calendar ca2 = Calendar.getInstance();
        ca1.setTime(date1);//from   ww  w  . j  a  v a  2s.  c  o  m
        ca2.setTime(date2);
        int day1 = ca1.get(Calendar.DAY_OF_MONTH);
        int year1 = ca1.get(Calendar.YEAR);
        int month1 = ca1.get(Calendar.MONTH);
        int day2 = ca2.get(Calendar.DAY_OF_MONTH);
        int year2 = ca2.get(Calendar.YEAR);
        int month2 = ca2.get(Calendar.MONTH);
        ca1.set(year1, month1, day1);
        ca2.set(year2, month2, day2);
        int distanceMin = (int) ((ca1.getTimeInMillis() - ca2.getTimeInMillis()));
        return distanceMin;
    }
}

Related

  1. compareToMonthByDate(Date startDate, Date endDate)
  2. compareTwoDate(Date beforeDate, Date afterDate)
  3. compareYear(java.util.Date date1, java.util.Date date2)
  4. compareYMD(Date begindate, Date enddate)
  5. compDate(Date date1, Date date2)
  6. getCompareDate(Date startDate, Date endDate)
  7. getCompareDate(String strDate1, String strDate2, String pFormat)
  8. getCompareDate(String strDate1, String strDate2, String pFormat)
  9. getCompareDateNum(String sDateValue1, String sDateValue2)