Here you can find the source of getBeteenDays(String begin, String end, String format)
public static Integer getBeteenDays(String begin, String end, String format) throws ParseException
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static Integer getBeteenDays(String begin, String end, String format) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Calendar cal = Calendar.getInstance(); cal.setTime(sdf.parse(begin));//from w ww.j a v a 2 s. co m long time1 = cal.getTimeInMillis(); cal.setTime(sdf.parse(end)); long time2 = cal.getTimeInMillis(); long between_days = (time2 - time1) / (1000 * 3600 * 24); return Integer.parseInt(String.valueOf(between_days)) + 1; } }