Android Hour Get betweenHours(int tuntil_h, int tfrom_h, int tuntil_m, int tfrom_m, int c_hour, int c_min)

Here you can find the source of betweenHours(int tuntil_h, int tfrom_h, int tuntil_m, int tfrom_m, int c_hour, int c_min)

Description

Check if current time is between given hours

Parameter

Parameter Description
tuntil_h hour until
tfrom_h hour from
tuntil_m minute of tuntil_h
tfrom_m minute of tfrom_h
c_hour current hour
c_min current minute

Return

true if current time is in given range, false otherwise

Declaration

public static boolean betweenHours(int tuntil_h, int tfrom_h,
        int tuntil_m, int tfrom_m, int c_hour, int c_min) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww w  . j ava2  s . c  o m
     * Check if current time is between given hours
     * 
     * @param tuntil_h
     *            hour until
     * @param tfrom_h
     *            hour from
     * @param tuntil_m
     *            minute of tuntil_h
     * @param tfrom_m
     *            minute of tfrom_h
     * @param c_hour
     *            current hour
     * @param c_min
     *            current minute
     * @return true if current time is in given range, false otherwise
     */
    public static boolean betweenHours(int tuntil_h, int tfrom_h,
            int tuntil_m, int tfrom_m, int c_hour, int c_min) {

        // if midnight is in cycle
        if (tuntil_h < tfrom_h) {
            // current hour is in cycle
            if (c_hour <= tuntil_h)
                c_hour += 24;
            tuntil_h += 24;
        }
        int ctime = c_hour * 60 + c_min;
        int u_time = tuntil_h * 60 + tuntil_m;
        int f_time = tfrom_h * 60 + tfrom_m;
        return (ctime > f_time && ctime < u_time);
    }
}

Related

  1. getHour()
  2. isBeforeHourTime(String compactTime, int hour)