Here you can find the source of compareTime(String time1, String time2)
public static int compareTime(String time1, String time2)
//package com.java2s; //License from project: Apache License import java.util.*; import java.text.*; public class Main { public static int compareTime(String time1, String time2) { Date newDate1 = parseDate("1990-01-01 " + time1, "yyyy-MM-dd HH:mm:ss"); Date newDate2 = parseDate("1990-01-01 " + time2, "yyyy-MM-dd HH:mm:ss"); if (getMillis(newDate1) - getMillis(newDate2) > 0) return 1; else if (getMillis(newDate1) - getMillis(newDate2) < 0) return -1; return 0; }/* w ww . j a v a 2s . c om*/ public static Date parseDate(java.sql.Date date) { return date; } public static java.util.Date parseDate(String dateStr, String formatStr) { SimpleDateFormat format = new SimpleDateFormat(formatStr); try { return format.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); return null; } } public static long getMillis(Date date) { java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(date); return c.getTimeInMillis(); } }