1.
//获取时间差 public static void dateDiff(String desc,String startTime, String endTime) { SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long between = 0; try { java.util.Date begin = dfs.parse(startTime); java.util.Date end = dfs.parse(endTime); between = (end.getTime() - begin.getTime());// 得到两者的毫秒数 long day = between / (24 * 60 * 60 * 1000); long hour = (between / (60 * 60 * 1000) - day * 24); long min = ((between / (60 * 1000)) - day * 24 * 60 - hour * 60); long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60); System.out.println(desc+" 开始时间:"+startTime+" 结束时间:"+endTime); System.out.println(desc+" 总该耗时:"+day + "天" + hour + "小时" + min + "分" + s + "秒"); } catch (Exception ex) { ex.printStackTrace(); } }