首页 > 编程语言 > 详细

Java 判断时间是否超过24小时

时间:2020-02-09 19:20:12      阅读:720      评论:0      收藏:0      [点我收藏+]
/**判断是否超过多少小时 如: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;

        }

    }

 

Java 判断时间是否超过24小时

原文:https://www.cnblogs.com/w-yu-chen/p/12287765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!