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 <= 24) {

            return true;//是小於等於 hour 小時

        } else {

            return false;

        }

    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM