Here you can find the source of getDaysBetweenTwoDays(String dateFrom, String dateEnd)
public static String getDaysBetweenTwoDays(String dateFrom, String dateEnd)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String getDaysBetweenTwoDays(String dateFrom, String dateEnd) { Date dtFrom = null;//from w w w . j a v a2 s . com Date dtEnd = null; dtFrom = toDate(dateFrom, "yyyy-MM-dd"); dtEnd = toDate(dateEnd, "yyyy-MM-dd"); long begin = dtFrom.getTime(); long end = dtEnd.getTime(); long inter = end - begin; if (inter < 0) { inter = inter * (-1); } long dateMillSec = 24 * 60 * 60 * 1000; long dateCnt = inter / dateMillSec; long remainder = inter % dateMillSec; if (remainder != 0) { dateCnt++; } return String.valueOf(dateCnt); } public static Date toDate(String sDate, String sFmt) { Date dt = null; try { dt = new SimpleDateFormat(sFmt).parse(sDate); } catch (ParseException e) { return dt; } return dt; } }