Here you can find the source of getDiffDays(String startDate, String endDate)
public static int getDiffDays(String startDate, String endDate)
//package com.java2s; //License from project: Apache License 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 w ww . jav a 2s . co m 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; } }