Here you can find the source of getDifferenceOfDays(String dateFromStr, String dateToStr, String dateFormat)
public static int getDifferenceOfDays(String dateFromStr, String dateToStr, String dateFormat)
//package com.java2s; import java.text.*; import java.util.TimeZone; public class Main { public static final String DEFAULT_CHAR_DATE_YMD_FORMAT = "yyyyMMdd"; public static int getDifferenceOfDays(java.util.Date dateFrom, java.util.Date dateTo) { return new Long((dateTo.getTime() - dateFrom.getTime()) / 1000 / 60 / 60 / 24).intValue(); }/* w w w. ja v a 2 s .c o m*/ public static int getDifferenceOfDays(String dateFromStr, String dateToStr, String dateFormat) { java.util.Date dateFrom = parseDate(dateFromStr, dateFormat); java.util.Date dateTo = parseDate(dateToStr, dateFormat); return getDifferenceOfDays(dateFrom, dateTo); } public static int getDifferenceOfDays(String dateFromStr, String dateToStr) { return getDifferenceOfDays(dateFromStr, dateToStr, DEFAULT_CHAR_DATE_YMD_FORMAT); } public static java.util.Date parseDate(String value, String pattern) { try { TimeZone tz = TimeZone.getDefault(); String dateFormat = pattern; SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); sdf.setTimeZone(tz); // Parse date java.util.Date parsed = null; parsed = sdf.parse(value); return parsed; } catch (ParseException e) { return null; } } }