/** * 计算有效时间 * @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; }