两个区间相差多少小时/分钟

public long getExpireDate(String startDate, String endDate) {
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH");
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        try {
            // 获得两个时间的毫秒时间差异/一小时的毫秒数=相差多少个小时
            long hour = (sd.parse(endDate).getTime() - sd.parse(startDate).getTime()) / nh;// 计算差多少小时
            return hour;
        } catch (ParseException e) {
            logger.error("Setting issueStartDate too long ");
            return -1l;
        }
    }

  

posted @ 2022-11-02 19:43  老王的日常  阅读(14)  评论(0)    收藏  举报