`
Dong_Android
  • 浏览: 26750 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

计算两个时间之间的间隔天数 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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics