Here you can find the source of getDateDiff(String startDate, String endDate)
public static long getDateDiff(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 long getDateDiff(String startDate, String endDate) { long diff = 0; try {/*from www. j av a 2 s .c om*/ Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(startDate); Date date2 = new SimpleDateFormat("yyyy-MM-dd").parse(endDate); diff = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) > 0 ? (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) : (date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000); } catch (ParseException e) { } return diff; } public static long getDateDiff(Date date1, Date date2) { if (date1 == null || date2 == null) { return 0L; } long diff = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) > 0 ? (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) : (date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000); return diff; } }