计算两个日期的时间差

/**
     * 计算有效时间
     * @param ftime  最早时间
     * @param ltime  最晚时间
     * @return
     */
    public String getUsefulTime(List<Map<String,Object>>timelist){
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        String usefultime="";
        Date firstTime=null;
        Date lastTime=null;
        //计算有效时间差
        if(timelist.get(0).get("min(bs.testtime)")!=null&&timelist.get(0).get("max(bs.testtime)")!=null){
            try {
                firstTime=sdf.parse(timelist.get(0).get("min(bs.testtime)").toString().substring(0,19));
                lastTime=sdf.parse(timelist.get(0).get("max(bs.testtime)").toString().substring(0,19));
                long times = lastTime.getTime()-firstTime.getTime();//毫秒差
                long day = times / nd;//相差的天
                long hour = times % nd / nh;     //获取相差的小时数
                long min = times % nd % nh / nm;  //获取相差的分钟数
                if(day>0){
                        hour=hour+day*24;
                    }
                usefultime=hour+"小时"+min+"分钟";
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            usefultime = 0+"小时"+0+"分钟";
        }
        
        return usefultime;
    }

 

转载于:https://www.cnblogs.com/qtt1994/p/10522647.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值