Java Date Between betweenHour(Date date, int hour)

Here you can find the source of betweenHour(Date date, int hour)

Description

between Hour

License

Open Source License

Declaration

public static boolean betweenHour(Date date, int hour) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static boolean betweenHour(Date date, int hour) {
        Calendar calendar = getCalendarFromDate(date);
        calendar.add(Calendar.HOUR, hour);
        Calendar now = getDefaultCalendar();
        return calendar.after(now);
    }//from  ww w .j  a v  a  2 s . c  o m

    /**
     * get calendar from date
     *
     * @param date the passing date
     * @return the calendar instance
     */
    public static Calendar getCalendarFromDate(Date date) {
        Calendar calendar = getDefaultCalendar();
        calendar.setTime(date);
        return calendar;
    }

    /**
     * get the default calendar
     *
     * @return the calendar instance
     */
    public static Calendar getDefaultCalendar() {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        return calendar;
    }
}

Related

  1. between(Date d, Date startDate, Date endDate)
  2. between(Date kezdet, Date veg, Date datum)
  3. between(Date since, Date until, Date dateIn, Date dateOut)
  4. between(Date smdate, Date bdate)
  5. betweenDate(String from, String to)
  6. betweenInDay(Date date, Date start, Date end)
  7. betweenStartDateAndEndDate(Date startDate, Date endDate)
  8. betweenStrict(Date kezdet, Date datum, Date veg)
  9. betweenTwoDates(Date date1, Date date2)