Here you can find the source of getIntevalDays(String startDate, String endDate)
public static long getIntevalDays(String startDate, String endDate)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public final static String YYYY_MM_DD = "yyyy-MM-dd"; public static long getIntevalDays(String startDate, String endDate) { try {/*from w w w. ja va 2 s . co m*/ return getIntevalDays(parse(startDate, YYYY_MM_DD), parse(endDate, YYYY_MM_DD)); } catch (Exception ee) { return 0l; } } public static long getIntevalDays(Date startDate, Date endDate) { try { Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); endCalendar.setTime(endDate); long diff = endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis(); return (diff / (1000 * 60 * 60 * 24)); } catch (Exception ee) { return 0l; } } public static Date parse(String strDate, String pattern) throws ParseException { try { return getFormatter(pattern).parse(strDate); } catch (ParseException pe) { throw new ParseException("Method parse in Class DateUtil err: parse strDate fail.", pe.getErrorOffset()); } } private static SimpleDateFormat getFormatter(String parttern) { return new SimpleDateFormat(parttern); } }