Here you can find the source of compareDate(String sFirstDate, String sSecondDate)
public static long compareDate(String sFirstDate, String sSecondDate)
//package com.java2s; //License from project: Apache License import java.util.Calendar; public class Main { public static long compareDate(String sFirstDate, String sSecondDate) { long time1 = convertDateTimeToSysTime(sFirstDate); long time2 = convertDateTimeToSysTime(sSecondDate); long nTime = (time1 - time2); final long nConst = (24 * 60 * 60 * 1000); if (nTime % nConst == 0) { return nTime / nConst; }//from w w w . j a v a 2 s .c o m return (nTime / nConst) + 1; } public static long convertDateTimeToSysTime(String sDateTime) { int nYear = Integer.parseInt(sDateTime.substring(0, 4)); int nMonth = Integer.parseInt(sDateTime.substring(4, 6)); int nDay = Integer.parseInt(sDateTime.substring(6, 8)); int nHour = 0, nMinute = 0, nSecond = 0; if (sDateTime.length() == 14) { nHour = Integer.parseInt(sDateTime.substring(8, 10)); nMinute = Integer.parseInt(sDateTime.substring(10, 12)); nSecond = Integer.parseInt(sDateTime.substring(12, 14)); } Calendar calendar = Calendar.getInstance(); calendar.set(nYear, nMonth - 1, nDay, nHour, nMinute, nSecond); return calendar.getTime().getTime(); } }