计算两个时间之间的间隔天数 time2大时间, time1小时间

/**
* 计算两个时间之间的间隔天数 time2大时间, time1小时间
* @param time2
* @param time1
* @return
*/
public static int CalculateIntervalDays(String time2, String time1){
int IntervalDays = 0;
Date date2 = null;
Date date1 = null;
try {
Calendar calendar = Calendar.getInstance();
date2 = DateUtil.ToDateTime(time2, 1);// 将String类型的时间格式转换为date类型
date1 = DateUtil.ToDateTime(time1, 1);// 将String类型的时间格式转换为date类型
IntervalDays =  Integer.parseInt(String.valueOf((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000)));
} catch (ParseException e) {
e.printStackTrace();
}
return (IntervalDays < 0) ? 0 : IntervalDays;
}

猜你喜欢

转载自dong-android.iteye.com/blog/2207469