Here you can find the source of compareTime(String time1, String time2)
public static int compareTime(String time1, String time2) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static int compareTime(String time1, String time2) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_DATE_PATTERN); Date date1 = sdf.parse(time1); Date date2 = sdf.parse(time2); long result = date1.getTime() - date2.getTime(); if (result > 0) { return 1; } else if (result == 0) { return 0; } else {/*from w w w . j a v a 2 s .c o m*/ return -1; } } }