Java Day Between getTodayDiff(String diffDate)

Here you can find the source of getTodayDiff(String diffDate)

Description

get Today Diff

License

Apache License

Declaration

public static final int getTodayDiff(String diffDate) 

Method Source Code

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

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

public class Main {

    public static final int getTodayDiff(String diffDate) {
        int diffCnt = 0;
        int yyyy = 0;
        int mm = 0;
        int dd = 0;
        Date today = new Date();

        yyyy = Integer.parseInt(diffDate.substring(0, 4));
        mm = Integer.parseInt(diffDate.substring(4, 6));
        dd = Integer.parseInt(diffDate.substring(6, 8));

        Calendar cal = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal.setTime(today);/* w w w  .ja v a  2s  . co m*/
        cal.add(Calendar.MONTH, 1);
        cal2.set(yyyy, mm, dd);

        if (cal2.before(cal)) {
            while (!cal2.after(cal)) {
                ++diffCnt;
                cal2.add(Calendar.DATE, 1);
            }
        } else {
            while (!cal2.before(cal)) {
                --diffCnt;
                cal2.add(Calendar.DATE, -1);
            }
        }

        return diffCnt;
    }
}

Related

  1. getMonthsDifference(Date earlierDate, Date laterDate)
  2. getNumDaysDiffExclTime(Date date1, Date date2)
  3. getTimeDifference(Date d1, Date d2)
  4. getTimeDifference(Date date1, Date date2)
  5. getTimeDifference(Date otherDate)
  6. getWorkingDaysBetween(Date fromDate, Date toDate)
  7. getYearDiff(Date date1, Date date2)
  8. getYearsDifference(Date startTime, Date endTime)
  9. hourDiff(Date firstDate, Date lastDate)