Java 判断是否超过多少小时 如:24

 /**判断是否超过多少小时 如:24
     *
     * @param tableTime 业务时间
     * @param hour 多少小时
     * @return boolean
     * @throws Exception
     */
    public static boolean judgmentDate(String tableTime, Integer hour) throws Exception {
        String currentTime = DateUtil.getCurrentTime("yyyy-MM-dd HH:mm:ss");//当前时间

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d HH:mm:ss");

        Date start = sdf.parse(tableTime);

        Date end = sdf.parse(currentTime);

        long cha = end.getTime() - start.getTime();

        if (cha < 0) {

            return false;
        }

        double result = cha * 1.0 / (1000 * 60 * 60);

        if (result <= hour) {

            return true;//是小于等于 hour 小时

        } else {

            return false;

        }

    }

猜你喜欢

转载自www.cnblogs.com/w-yu-chen/p/12565771.html