Here you can find the source of isDateTimeAfter(String startDate, String startTime, String endDate, String endTime)
public static boolean isDateTimeAfter(String startDate, String startTime, String endDate, String endTime)
//package com.java2s; import java.util.ArrayList; import java.util.Date; import java.util.StringTokenizer; public class Main { public static boolean isDateTimeAfter(String startDate, String startTime, String endDate, String endTime) { Date startD = dateTimeToDateObj(startDate, startTime); Date endD = dateTimeToDateObj(endDate, endTime); if (startD.getTime() >= endD.getTime()) { return false; } else {// ww w .j av a 2 s. com return true; } } public static Date dateTimeToDateObj(String date, String time) { java.util.Calendar cal = java.util.Calendar.getInstance(); int[] dateTokens; dateTokens = tokenizeDate(date); cal.set(java.util.Calendar.YEAR, dateTokens[2]); cal.set(java.util.Calendar.MONTH, dateTokens[0] - 1); cal.set(java.util.Calendar.DATE, dateTokens[1]); int[] timeTokens; timeTokens = tokenizeTime(time); if (timeTokens[0] == 12) { timeTokens[0] -= 12; } cal.set(java.util.Calendar.HOUR, timeTokens[0]); cal.set(java.util.Calendar.MINUTE, timeTokens[1]); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); cal.set(java.util.Calendar.AM_PM, timeTokens[2]); return new Date(cal.getTimeInMillis()); } public static int[] tokenizeDate(String date) { StringTokenizer st = new StringTokenizer(date, "-/"); ArrayList<Integer> al = new ArrayList<Integer>(); while (st.hasMoreTokens()) { al.add(Integer.parseInt(st.nextToken())); } int[] tokenList = new int[3]; for (int i = 0; i < al.size(); i++) { tokenList[i] = al.get(i); } return tokenList; } public static int[] tokenizeTime(String time) { String newTime = time.replaceAll(":", " ").replaceAll("PM", "1") .replaceAll("AM", "0"); // 11:27 PM will become "11 17 1" StringTokenizer st = new StringTokenizer(newTime, " "); ArrayList<Integer> al = new ArrayList<Integer>(); while (st.hasMoreTokens()) { al.add(Integer.parseInt(st.nextToken())); } int[] tokenList = new int[3]; for (int i = 0; i < al.size(); i++) { tokenList[i] = al.get(i); } return tokenList; } }