();
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
day = diff / (24 * 60 * 60 * 1000);
hour = (diff / (60 * 60 * 1000) - day * 24);
min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
map.put("day", day < 10 ? "0" + day : day);
map.put("hour", hour < 10 ? "0" + hour : hour);
map.put("min", min < 10 ? "0" + min : min);
map.put("sec", sec < 10 ? "0" + sec : sec);
map.put("millisecond", diff);
return map;
}
//两时间差
public static long getDifferenceTimeNum(Date one, Date two) {
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
return diff;
}
public static boolean isSameDate(Date date1, Date date2) {
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
boolean isSameYear = cal1.get(Calendar.YEAR) == cal2
.get(Calendar.YEAR);
boolean isSameMonth = isSameYear
&& cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
boolean isSameDate = isSameMonth
&& cal1.get(Calendar.DAY_OF_MONTH) == cal2
.get(Calendar.DAY_OF_MONTH);
return isSameDate;
}
/**
* @param sformat 时间格式
* @param beforeDay 如果为负数即当前时间前beforeDay天,如果为正数则为当前时间后beforeDay天
* @return 方法说明:
*
* 创立日期:2018年5月16日 下午3:51:09
* 创建人:yangcan
*/
public static String getBeforeDate(String sformat, int beforeDay) {
Calendar calendar = Calendar.getInstance(); //得到日历
calendar.setTime(new Date());//把当前时间赋给日历
calendar.add(Calendar.DAY_OF_MONTH, beforeDay); //设置为当前时间前beforeDay天
SimpleDateFormat formatter = new SimpleDateFormat(sformat);
String dateString = formatter.format(calendar.getTime());
return dateString;
}
/**
* @param date 传入时间
* @param hour 传入时间加小时
* @param minute 传入时间加分钟
* @return 方法说明:返回传入时间加小时,分钟后的时间
*
* 创立日期:2018年6月10日 下午3:19:32
* 创建人:yangcan
*/
public static Date getAddHour(Date date, int hour, int minute) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR, hour);
cal.add(Calendar.MINUTE, minute);
return cal.getTime();
}
public static List