Here you can find the source of diffInDays(Date date1, Date date2)
public static Long diffInDays(Date date1, Date date2)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; public class Main { static final String DATEFORMAT = "yyyy-MM-dd"; public static Long diffInDays(Date date1, Date date2) { try {/* ww w . j ava 2 s .com*/ SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT); String lastUpdateInUTCString = sdf.format(date1); String nowInUTCString = sdf.format(date2); Date lastUpdateInUTC; lastUpdateInUTC = stringDateToDate(lastUpdateInUTCString); Date nowInUTC = stringDateToDate(nowInUTCString); long nowInUTCMilis = nowInUTC.getTime(); long lastUpdateInUTCMilis = lastUpdateInUTC.getTime(); long diff = nowInUTCMilis - lastUpdateInUTCMilis; TimeUnit tu = TimeUnit.DAYS; long diffinDays = tu.convert(diff, TimeUnit.MILLISECONDS); return diffinDays; } catch (ParseException e) { return Long.MIN_VALUE; } } public static String format(Date date) { SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT); return dateFormat.format(date); } public static Date stringDateToDate(String StrDate) throws ParseException { Date dateToReturn = null; SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT); try { dateToReturn = (Date) dateFormat.parse(StrDate); } catch (ParseException e) { e.printStackTrace(); } return dateToReturn; } }