Here you can find the source of compareDate(String d1, String d2)
public static int compareDate(String d1, String d2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static int compareDate(String d1, String d2) { if (d1.trim().length() > 10) { d1 = d1.split(" ")[0]; }//from www. j av a 2 s .c o m if (d2.trim().length() > 10) { d2 = d2.split(" ")[0]; } GregorianCalendar date1 = new GregorianCalendar(); String[] temp1 = d1.split("-"); date1.set(Calendar.YEAR, Integer.parseInt(temp1[0])); date1.set(Calendar.MONTH, Integer.parseInt(temp1[1].substring(0, 1).equals("0") ? temp1[1].substring(1) : temp1[1]) - 1); date1.set(Calendar.DATE, Integer.parseInt(temp1[2].substring(0, 1).equals("0") ? temp1[2].substring(1) : temp1[2])); GregorianCalendar date2 = new GregorianCalendar(); String[] temp2 = d2.split("-"); date2.set(Calendar.YEAR, Integer.parseInt(temp2[0])); date2.set(Calendar.MONTH, Integer.parseInt(temp2[1].substring(0, 1).equals("0") ? temp2[1].substring(1) : temp2[1]) - 1); date2.set(Calendar.DATE, Integer.parseInt(temp2[2].substring(0, 1).equals("0") ? temp2[2].substring(1) : temp2[2])); int result = date1.compareTo(date2); return result; } }