Here you can find the source of compareDate(String sDate, String eDate, String formatStr)
public static int compareDate(String sDate, String eDate, String formatStr)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static int compareDate(Date sDate, Date eDate) { Calendar sC = Calendar.getInstance(); sC.setTime(sDate);//from w w w.j a va 2 s . co m Calendar eC = Calendar.getInstance(); eC.setTime(eDate); return sC.compareTo(eC); } public static int compareDate(String sDate, String eDate, String formatStr) { Date startDate = strToDate(sDate, formatStr); Date endDate = strToDate(eDate, formatStr); return compareDate(startDate, endDate); } public static Date strToDate(String dateStr, String formatStr) { Date date = null; try { SimpleDateFormat format = new SimpleDateFormat(formatStr); date = format.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } return date; } }