Java Calendar Different dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)

Here you can find the source of dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)

Description

date Diff

License

Open Source License

Declaration

static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) 

Method Source Code


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

import java.util.Calendar;

public class Main {
    static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) {
        int diff = 0;
        long savedDate = fromDate.getTimeInMillis();
        while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) {
            savedDate = fromDate.getTimeInMillis();
            fromDate.add(type, future ? 1 : -1);
            diff++;//from  ww  w.  j av  a  2 s  . c om
        }
        diff--;
        fromDate.setTimeInMillis(savedDate);
        return diff;
    }
}

Related

  1. countDiffDay(Calendar c1, Calendar c2)
  2. countDiffMonth(Calendar cBegin, Calendar cEnd, boolean isRoundUp)
  3. datediff(Calendar c1, Calendar c2)
  4. dateDiff(int type, Calendar fromDate, Calendar toDate)
  5. dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
  6. dateDiff(long dateUtilitiesUnitField, Calendar firstDate, Calendar secondDate)
  7. dateDifferenceInMin(Calendar startDate, Calendar stopDate)
  8. diff(Calendar value1, Calendar value2, int millisInCondition)