/**
* 计算两个日期相差天数
*
* @param date1
* @param date2
* @return
*/
public static Integer getDaysDifference(Date date1, Date date2) {
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss");
long t1 = 0L;
long t2 = 0L;
try {
t1 = timeFormat.parse(getTimeStampNumberFormat(date1)).getTime();
} catch (ParseException e) {
e.printStackTrace();
}
try {
t2 = timeFormat.parse(getTimeStampNumberFormat(date2)).getTime();
} catch (ParseException e) {
e.printStackTrace();
}
// 因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
int days = (int) ((t1 - t2) / 3600000 / 24);
return days + 1;
}
计算两个日期相差天数
最新推荐文章于 2024-04-09 11:03:27 发布
2877

被折叠的 条评论
为什么被折叠?



