/**
* 计算时间差
* @param beginTime 开始时间
* @param endTime 结束时间
* @param beginTimeFormat 开始时间格式
* @param endTimeFormat 结束时间格式
* @param returnTime 输出类型 0:天,1:小时,2:分钟,3:秒,4:毫秒
*/
public static Long timeDifference(String beginTime, TimeFormatEnum beginTimeFormat,
String endTime, TimeFormatEnum endTimeFormat,
Integer returnTime) {
DateTimeFormatter beginFormatter = DateTimeFormat.forPattern(beginTimeFormat.getFormat());
DateTimeFormatter endTFormatter = DateTimeFormat.forPattern(endTimeFormat.getFormat());
DateTime begin = DateTime.parse(beginTime, beginFormatter);
DateTime end = DateTime.parse(endTime, endTFormatter);
// 计算区间毫秒数
Duration etime = new Duration(begin, end);
switch (returnTime) {
case 0:
return etime.getStandardDays();
case 1:
return etime.getStandardHours();
case 2:
return etime.getStandardMinutes();
case 3:
return etime.getStandardSeconds();
default:
return etime.getMillis();
}
}