Here you can find the source of getDiffDays(String startDate, String endDate)
public static int getDiffDays(String startDate, String endDate)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int getDiffDays(String startDate, String endDate) { long diff = 0; SimpleDateFormat ft = null; if (startDate.indexOf("/") > 0 && endDate.indexOf("/") > 0) { ft = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); }/*from www. ja v a 2 s. c om*/ if (startDate.indexOf("-") > 0 && endDate.indexOf("-") > 0) { ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } try { Date sDate = ft.parse(startDate + " 00:00:00"); Date eDate = ft.parse(endDate + " 00:00:00"); diff = eDate.getTime() - sDate.getTime(); diff = diff / 86400000;// 1000*60*60*24; } catch (ParseException e) { e.printStackTrace(); } return (int) diff; } }