码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-02-09 18:37:13      阅读:534      评论:0      收藏:0      [点我收藏+]

标签:过多   当前时间   except   color   EDA   for   cep   string   integer   

/**判断是否超过多少小时 如: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小时

标签:过多   当前时间   except   color   EDA   for   cep   string   integer   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!