Here you can find the source of compareDate(String startDate, String endDate, String strFormat)
public static int compareDate(String startDate, String endDate, String strFormat)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.util.*; public class Main { public static int compareDate(String startDate, String endDate, String strFormat) { java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(strFormat); Calendar start = Calendar.getInstance(); Date tempstartdate;/*from ww w . j a v a 2 s. co m*/ Calendar end = null; try { tempstartdate = formatter.parse(startDate); start.setTime(tempstartdate); end = Calendar.getInstance(); Date tempenddate = formatter.parse(endDate); end.setTime(tempenddate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (start.before(end)) { return -1; } else if (start.after(end)) { return 1; } else { return 0; } } }