Android Time Compare isOnRange(String fromTime, String toTime)

Here you can find the source of isOnRange(String fromTime, String toTime)

Description

is On Range

Declaration

public static boolean isOnRange(String fromTime, String toTime) 

Method Source Code

//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;
    }
}

Related

  1. isPastDateTime(DateTime target)
  2. isSameDate(Time t1, Time t2)
  3. isSameLocalTime(Calendar cal1, Calendar cal2)
  4. isSameMonth(Time t1, Time t2)
  5. isTimeAfter(String webTime, String localTime)
  6. javaToDosTime(long time)
  7. timeEnd(String tag, long threshold)