Here you can find the source of getBetweenDays(String strFromDate, String strToDate)
public static int getBetweenDays(String strFromDate, String strToDate)
//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; } } }