Java Date Between getBetweenDays(String strFromDate, String strToDate)

Here you can find the source of getBetweenDays(String strFromDate, String strToDate)

Description

get Between Days

License

Apache License

Declaration

public static int getBetweenDays(String strFromDate, String strToDate) 

Method Source Code

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

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {

    public static int getBetweenDays(String strFromDate, String strToDate) {
        try {//from ww w .  j  a va 2  s .c  om
            Calendar clFrom = new GregorianCalendar();
            int iYear = Integer.parseInt(strFromDate.substring(0, 4));
            int iMonth = Integer.parseInt(strFromDate.substring(4, 6));
            int iDay = Integer.parseInt(strFromDate.substring(6, 8));
            clFrom.set(iYear, iMonth, iDay, 0, 0, 0);
            Calendar clTo = new GregorianCalendar();
            iYear = Integer.parseInt(strToDate.substring(0, 4));
            iMonth = Integer.parseInt(strToDate.substring(4, 6));
            iDay = Integer.parseInt(strToDate.substring(6, 8));
            clTo.set(iYear, iMonth, iDay, 0, 0, 0);
            long llTmp = clTo.getTime().getTime() - clFrom.getTime().getTime();
            return new Long(llTmp / 1000 / 3600 / 24).intValue();
        } catch (Exception e) {
            return Integer.MIN_VALUE;
        }
    }
}

Related

  1. daysBetweenMidnight(final Date startDate, final Date endDate)
  2. getBetweenDate(Date startDate, Date endDate)
  3. getBetweenDate(String d1, String d2)
  4. getBetweenDateBuckets(Date from, Date to)
  5. getBetweenDates(Date fromDate, Date toDate )
  6. getBetweenMonths(Date date1, Date date2)
  7. getBetweenTime(Date begin, Date end, int field)
  8. getBetweenWorkDate(int amount, Date beginDate)
  9. isBetween(Date check, Date from, Date to)