Here you can find the source of compareDate(String fistDate, String secondDate, String format)
public static boolean compareDate(String fistDate, String secondDate, String format) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static Map<String, SimpleDateFormat> formats = new HashMap(); public static boolean compareDate(String fistDate, String secondDate, String format) throws ParseException { boolean flag = false; Date fist = null;// ww w .j av a 2 s.com Date second = null; fist = getDateFromString(fistDate, format); second = getDateFromString(secondDate, format); if (fist.before(second)) { flag = true; } return flag; } public static Date getDateFromString(String date, String pattern) throws ParseException { SimpleDateFormat sDateFormat = getDateFormat(pattern); synchronized (sDateFormat) { return sDateFormat.parse(date); } } public static SimpleDateFormat getDateFormat(String pattern) { SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern); if (sDateFormat == null) { sDateFormat = new SimpleDateFormat(pattern); formats.put(pattern, sDateFormat); } return sDateFormat; } }