Here you can find the source of isOnRange(String fromTime, String toTime)
public static boolean isOnRange(String fromTime, String toTime)
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static boolean isOnRange(String fromTime, String toTime) { DateFormat dateFormat = new SimpleDateFormat("h:mm a"); try {/* w w w. j av a 2 s . c o m*/ Date date1, date2, dateNueva; date1 = dateFormat.parse(fromTime); date2 = dateFormat.parse(toTime); String now = dateFormat.format(new Date()); dateNueva = dateFormat.parse(now); if ((date1.compareTo(dateNueva) <= 0) && (date2.compareTo(dateNueva) >= 0)) { return true; } else { return false; } } catch (ParseException e) { e.printStackTrace(); } return false; } }